Xenomai  3.0.8
cluster.h
1 /*
2  * Copyright (C) 2010 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 
19 #ifndef _COPPERPLATE_CLUSTER_H
20 #define _COPPERPLATE_CLUSTER_H
21 
22 #include <boilerplate/hash.h>
23 #include <copperplate/syncobj.h>
24 
25 #ifdef CONFIG_XENO_PSHARED
26 
27 struct clusterobj {
28  pid_t cnode;
29  struct hashobj hobj;
30 };
31 
32 struct dictionary {
33  struct hash_table table;
34  struct hashobj hobj;
35 };
36 
37 struct cluster {
38  struct dictionary *d;
39 };
40 
41 struct syndictionary {
42  struct hash_table table;
43  struct syncobj sobj;
44  struct hashobj hobj;
45 };
46 
47 struct syncluster {
48  struct syndictionary *d;
49 };
50 
51 struct pvclusterobj {
52  struct pvhashobj hobj;
53 };
54 
55 struct pvcluster {
56  struct pvhash_table table;
57 };
58 
59 struct pvsyncluster {
60  struct pvcluster c;
61  struct syncobj sobj;
62 };
63 
64 static inline
65 const void *clusterobj_key(const struct clusterobj *cobj)
66 {
67  return __memptr(__main_heap, cobj->hobj.key);
68 }
69 
70 static inline
71 size_t clusterobj_keylen(const struct clusterobj *cobj)
72 {
73  return cobj->hobj.len;
74 }
75 
76 static inline
77 pid_t clusterobj_cnode(const struct clusterobj *cobj)
78 {
79  return cobj->cnode;
80 }
81 
82 static inline
83 const void *pvclusterobj_key(const struct pvclusterobj *cobj)
84 {
85  return cobj->hobj.key;
86 }
87 
88 static inline
89 size_t pvclusterobj_keylen(const struct pvclusterobj *cobj)
90 {
91  return cobj->hobj.len;
92 }
93 
94 static inline
95 pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj)
96 {
97  return -1;
98 }
99 
100 #else /* !CONFIG_XENO_PSHARED */
101 
102 struct clusterobj {
103  struct pvhashobj hobj;
104 };
105 
106 struct cluster {
107  struct pvhash_table table;
108 };
109 
110 struct syncluster {
111  struct cluster c;
112  struct syncobj sobj;
113 };
114 
115 #define pvclusterobj clusterobj
116 #define pvcluster cluster
117 #define pvsyncluster syncluster
118 
119 static inline
120 const void *clusterobj_key(const struct pvclusterobj *cobj)
121 {
122  return cobj->hobj.key;
123 }
124 
125 static inline
126 size_t clusterobj_keylen(const struct pvclusterobj *cobj)
127 {
128  return cobj->hobj.len;
129 }
130 
131 static inline
132 pid_t clusterobj_cnode(const struct pvclusterobj *cobj)
133 {
134  return -1;
135 }
136 
137 static inline
138 const void *pvclusterobj_key(const struct pvclusterobj *cobj)
139 {
140  return clusterobj_key(cobj);
141 }
142 
143 static inline
144 size_t pvclusterobj_keylen(const struct pvclusterobj *cobj)
145 {
146  return clusterobj_keylen(cobj);
147 }
148 
149 static inline
150 pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj)
151 {
152  return clusterobj_cnode(cobj);
153 }
154 
155 #endif /* !CONFIG_XENO_PSHARED */
156 
157 struct syncluster_wait_struct {
158  union {
159  dref_type(char *) name_ref;
160  const char *name;
161  };
162 };
163 
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167 
168 int pvcluster_init(struct pvcluster *c, const char *name);
169 
170 void pvcluster_destroy(struct pvcluster *c);
171 
172 int pvcluster_addobj(struct pvcluster *c, const char *name,
173  struct pvclusterobj *cobj);
174 
175 int pvcluster_addobj_dup(struct pvcluster *c, const char *name,
176  struct pvclusterobj *cobj);
177 
178 int pvcluster_delobj(struct pvcluster *c,
179  struct pvclusterobj *cobj);
180 
181 struct pvclusterobj *pvcluster_findobj(struct pvcluster *c,
182  const char *name);
183 
184 int pvcluster_walk(struct pvcluster *c,
185  int (*walk)(struct pvcluster *c,
186  struct pvclusterobj *cobj));
187 
188 int pvsyncluster_init(struct pvsyncluster *sc, const char *name);
189 
190 void pvsyncluster_destroy(struct pvsyncluster *sc);
191 
192 int pvsyncluster_addobj(struct pvsyncluster *sc, const char *name,
193  struct pvclusterobj *cobj);
194 
195 int pvsyncluster_delobj(struct pvsyncluster *sc,
196  struct pvclusterobj *cobj);
197 
198 int pvsyncluster_findobj(struct pvsyncluster *sc,
199  const char *name,
200  const struct timespec *timeout,
201  struct pvclusterobj **cobjp) __must_check;
202 
203 #ifdef CONFIG_XENO_PSHARED
204 
205 int cluster_init(struct cluster *c, const char *name);
206 
207 int cluster_addobj(struct cluster *c, const char *name,
208  struct clusterobj *cobj);
209 
210 int cluster_addobj_dup(struct cluster *c, const char *name,
211  struct clusterobj *cobj);
212 
213 int cluster_delobj(struct cluster *c,
214  struct clusterobj *cobj);
215 
216 struct clusterobj *cluster_findobj(struct cluster *c,
217  const char *name);
218 
219 int cluster_walk(struct cluster *c,
220  int (*walk)(struct cluster *c,
221  struct clusterobj *cobj));
222 
223 int syncluster_init(struct syncluster *sc, const char *name);
224 
225 int syncluster_addobj(struct syncluster *sc, const char *name,
226  struct clusterobj *cobj);
227 
228 int syncluster_delobj(struct syncluster *sc,
229  struct clusterobj *cobj);
230 
231 int syncluster_findobj(struct syncluster *sc,
232  const char *name,
233  const struct timespec *timeout,
234  struct clusterobj **cobjp) __must_check;
235 
236 #else /* !CONFIG_XENO_PSHARED */
237 
238 static inline int cluster_init(struct cluster *c, const char *name)
239 {
240  return pvcluster_init(c, name);
241 }
242 
243 static inline int cluster_addobj(struct cluster *c, const char *name,
244  struct clusterobj *cobj)
245 {
246  return pvcluster_addobj(c, name, cobj);
247 }
248 
249 static inline int cluster_addobj_dup(struct cluster *c, const char *name,
250  struct clusterobj *cobj)
251 {
252  return pvcluster_addobj_dup(c, name, cobj);
253 }
254 
255 static inline int cluster_delobj(struct cluster *c,
256  struct clusterobj *cobj)
257 {
258  return pvcluster_delobj(c, cobj);
259 }
260 
261 static inline struct clusterobj *cluster_findobj(struct cluster *c,
262  const char *name)
263 {
264  return pvcluster_findobj(c, name);
265 }
266 
267 static inline int cluster_walk(struct cluster *c,
268  int (*walk)(struct cluster *c,
269  struct clusterobj *cobj))
270 {
271  return pvcluster_walk(c, walk);
272 }
273 
274 static inline int syncluster_init(struct syncluster *sc,
275  const char *name)
276 {
277  return pvsyncluster_init(sc, name);
278 }
279 
280 static inline int syncluster_addobj(struct syncluster *sc,
281  const char *name,
282  struct clusterobj *cobj)
283 {
284  return pvsyncluster_addobj(sc, name, cobj);
285 }
286 
287 static inline int syncluster_delobj(struct syncluster *sc,
288  struct clusterobj *cobj)
289 {
290  return pvsyncluster_delobj(sc, cobj);
291 }
292 
293 static inline __must_check
294 int syncluster_findobj(struct syncluster *sc,
295  const char *name,
296  const struct timespec *timeout,
297  struct clusterobj **cobjp)
298 {
299  return pvsyncluster_findobj(sc, name, timeout, cobjp);
300 }
301 
302 #endif /* !CONFIG_XENO_PSHARED */
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif /* _COPPERPLATE_CLUSTER_H */