Xenomai 3.3.2
Loading...
Searching...
No Matches
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
27struct clusterobj {
28 pid_t cnode;
29 struct hashobj hobj;
30};
31
32struct dictionary {
33 struct hash_table table;
34 struct hashobj hobj;
35};
36
37struct cluster {
38 struct dictionary *d;
39};
40
41struct syndictionary {
42 struct hash_table table;
43 struct syncobj sobj;
44 struct hashobj hobj;
45};
46
47struct syncluster {
48 struct syndictionary *d;
49};
50
51struct pvclusterobj {
52 struct pvhashobj hobj;
53};
54
55struct pvcluster {
56 struct pvhash_table table;
57};
58
59struct pvsyncluster {
60 struct pvcluster c;
61 struct syncobj sobj;
62};
63
64static inline
65const void *clusterobj_key(const struct clusterobj *cobj)
66{
67 return __memptr(__main_heap, cobj->hobj.key);
68}
69
70static inline
71size_t clusterobj_keylen(const struct clusterobj *cobj)
72{
73 return cobj->hobj.len;
74}
75
76static inline
77pid_t clusterobj_cnode(const struct clusterobj *cobj)
78{
79 return cobj->cnode;
80}
81
82static inline
83const void *pvclusterobj_key(const struct pvclusterobj *cobj)
84{
85 return cobj->hobj.key;
86}
87
88static inline
89size_t pvclusterobj_keylen(const struct pvclusterobj *cobj)
90{
91 return cobj->hobj.len;
92}
93
94static inline
95pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj)
96{
97 return -1;
98}
99
100#else /* !CONFIG_XENO_PSHARED */
101
102struct clusterobj {
103 struct pvhashobj hobj;
104};
105
106struct cluster {
107 struct pvhash_table table;
108};
109
110struct syncluster {
111 struct cluster c;
112 struct syncobj sobj;
113};
114
115#define pvclusterobj clusterobj
116#define pvcluster cluster
117#define pvsyncluster syncluster
118
119static inline
120const void *clusterobj_key(const struct pvclusterobj *cobj)
121{
122 return cobj->hobj.key;
123}
124
125static inline
126size_t clusterobj_keylen(const struct pvclusterobj *cobj)
127{
128 return cobj->hobj.len;
129}
130
131static inline
132pid_t clusterobj_cnode(const struct pvclusterobj *cobj)
133{
134 return -1;
135}
136
137static inline
138const void *pvclusterobj_key(const struct pvclusterobj *cobj)
139{
140 return clusterobj_key(cobj);
141}
142
143static inline
144size_t pvclusterobj_keylen(const struct pvclusterobj *cobj)
145{
146 return clusterobj_keylen(cobj);
147}
148
149static inline
150pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj)
151{
152 return clusterobj_cnode(cobj);
153}
154
155#endif /* !CONFIG_XENO_PSHARED */
156
157struct syncluster_wait_struct {
158 union {
159 dref_type(char *) name_ref;
160 const char *name;
161 };
162};
163
164#ifdef __cplusplus
165extern "C" {
166#endif
167
168int pvcluster_init(struct pvcluster *c, const char *name);
169
170void pvcluster_destroy(struct pvcluster *c);
171
172int pvcluster_addobj(struct pvcluster *c, const char *name,
173 struct pvclusterobj *cobj);
174
175int pvcluster_addobj_dup(struct pvcluster *c, const char *name,
176 struct pvclusterobj *cobj);
177
178int pvcluster_delobj(struct pvcluster *c,
179 struct pvclusterobj *cobj);
180
181struct pvclusterobj *pvcluster_findobj(struct pvcluster *c,
182 const char *name);
183
184int pvcluster_walk(struct pvcluster *c,
185 int (*walk)(struct pvcluster *c,
186 struct pvclusterobj *cobj));
187
188int pvsyncluster_init(struct pvsyncluster *sc, const char *name);
189
190void pvsyncluster_destroy(struct pvsyncluster *sc);
191
192int pvsyncluster_addobj(struct pvsyncluster *sc, const char *name,
193 struct pvclusterobj *cobj);
194
195int pvsyncluster_delobj(struct pvsyncluster *sc,
196 struct pvclusterobj *cobj);
197
198int 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
205int cluster_init(struct cluster *c, const char *name);
206
207int cluster_addobj(struct cluster *c, const char *name,
208 struct clusterobj *cobj);
209
210int cluster_addobj_dup(struct cluster *c, const char *name,
211 struct clusterobj *cobj);
212
213int cluster_delobj(struct cluster *c,
214 struct clusterobj *cobj);
215
216struct clusterobj *cluster_findobj(struct cluster *c,
217 const char *name);
218
219int cluster_walk(struct cluster *c,
220 int (*walk)(struct cluster *c,
221 struct clusterobj *cobj));
222
223int syncluster_init(struct syncluster *sc, const char *name);
224
225int syncluster_addobj(struct syncluster *sc, const char *name,
226 struct clusterobj *cobj);
227
228int syncluster_delobj(struct syncluster *sc,
229 struct clusterobj *cobj);
230
231int 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
238static inline int cluster_init(struct cluster *c, const char *name)
239{
240 return pvcluster_init(c, name);
241}
242
243static inline int cluster_addobj(struct cluster *c, const char *name,
244 struct clusterobj *cobj)
245{
246 return pvcluster_addobj(c, name, cobj);
247}
248
249static 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
255static inline int cluster_delobj(struct cluster *c,
256 struct clusterobj *cobj)
257{
258 return pvcluster_delobj(c, cobj);
259}
260
261static inline struct clusterobj *cluster_findobj(struct cluster *c,
262 const char *name)
263{
264 return pvcluster_findobj(c, name);
265}
266
267static 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
274static inline int syncluster_init(struct syncluster *sc,
275 const char *name)
276{
277 return pvsyncluster_init(sc, name);
278}
279
280static 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
287static inline int syncluster_delobj(struct syncluster *sc,
288 struct clusterobj *cobj)
289{
290 return pvsyncluster_delobj(sc, cobj);
291}
292
293static inline __must_check
294int 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 */