Xenomai  3.0-rc3
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/init.h>
24 #include <copperplate/syncobj.h>
25 
26 #ifdef CONFIG_XENO_PSHARED
27 
28 struct clusterobj {
29  pid_t cnode;
30  struct hashobj hobj;
31 };
32 
33 struct dictionary {
34  struct hash_table table;
35  struct hashobj hobj;
36 };
37 
38 struct cluster {
39  struct dictionary *d;
40 };
41 
42 struct syncluster {
43  struct cluster c;
44  struct syncobj *sobj;
45 };
46 
47 struct pvclusterobj {
48  struct pvhashobj hobj;
49 };
50 
51 struct pvcluster {
52  struct pvhash_table table;
53 };
54 
55 struct pvsyncluster {
56  struct pvcluster c;
57  struct syncobj sobj;
58 };
59 
60 #else /* !CONFIG_XENO_PSHARED */
61 
62 struct clusterobj {
63  struct pvhashobj hobj;
64 };
65 
66 struct cluster {
67  struct pvhash_table table;
68 };
69 
70 struct syncluster {
71  struct cluster c;
72  struct syncobj sobj;
73 };
74 
75 #define pvclusterobj clusterobj
76 #define pvcluster cluster
77 #define pvsyncluster syncluster
78 
79 #endif /* !CONFIG_XENO_PSHARED */
80 
81 struct syncluster_wait_struct {
82  const char *name;
83 };
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
89 int pvcluster_init(struct pvcluster *c, const char *name);
90 
91 void pvcluster_destroy(struct pvcluster *c);
92 
93 int pvcluster_addobj(struct pvcluster *c, const char *name,
94  struct pvclusterobj *cobj);
95 
96 int pvcluster_addobj_dup(struct pvcluster *c, const char *name,
97  struct pvclusterobj *cobj);
98 
99 int pvcluster_delobj(struct pvcluster *c,
100  struct pvclusterobj *cobj);
101 
102 struct pvclusterobj *pvcluster_findobj(struct pvcluster *c,
103  const char *name);
104 
105 int pvsyncluster_init(struct pvsyncluster *sc, const char *name);
106 
107 void pvsyncluster_destroy(struct pvsyncluster *sc);
108 
109 int pvsyncluster_addobj(struct pvsyncluster *sc, const char *name,
110  struct pvclusterobj *cobj);
111 
112 int pvsyncluster_delobj(struct pvsyncluster *sc,
113  struct pvclusterobj *cobj);
114 
115 int pvsyncluster_findobj(struct pvsyncluster *sc,
116  const char *name,
117  const struct timespec *timeout,
118  struct pvclusterobj **cobjp) __must_check;
119 
120 #ifdef CONFIG_XENO_PSHARED
121 
122 int cluster_init(struct cluster *c, const char *name);
123 
124 int cluster_addobj(struct cluster *c, const char *name,
125  struct clusterobj *cobj);
126 
127 int cluster_addobj_dup(struct cluster *c, const char *name,
128  struct clusterobj *cobj);
129 
130 int cluster_delobj(struct cluster *c,
131  struct clusterobj *cobj);
132 
133 struct clusterobj *cluster_findobj(struct cluster *c,
134  const char *name);
135 
136 int syncluster_init(struct syncluster *sc, const char *name);
137 
138 int syncluster_addobj(struct syncluster *sc, const char *name,
139  struct clusterobj *cobj);
140 
141 int syncluster_delobj(struct syncluster *sc,
142  struct clusterobj *cobj);
143 
144 int syncluster_findobj(struct syncluster *sc,
145  const char *name,
146  const struct timespec *timeout,
147  struct clusterobj **cobjp) __must_check;
148 
149 #else /* !CONFIG_XENO_PSHARED */
150 
151 static inline int cluster_init(struct cluster *c, const char *name)
152 {
153  return pvcluster_init(c, name);
154 }
155 
156 static inline int cluster_addobj(struct cluster *c, const char *name,
157  struct clusterobj *cobj)
158 {
159  return pvcluster_addobj(c, name, cobj);
160 }
161 
162 static inline int cluster_addobj_dup(struct cluster *c, const char *name,
163  struct clusterobj *cobj)
164 {
165  return pvcluster_addobj_dup(c, name, cobj);
166 }
167 
168 static inline int cluster_delobj(struct cluster *c,
169  struct clusterobj *cobj)
170 {
171  return pvcluster_delobj(c, cobj);
172 }
173 
174 static inline struct clusterobj *cluster_findobj(struct cluster *c,
175  const char *name)
176 {
177  return pvcluster_findobj(c, name);
178 }
179 
180 static inline int syncluster_init(struct syncluster *sc,
181  const char *name)
182 {
183  return pvsyncluster_init(sc, name);
184 }
185 
186 static inline int syncluster_addobj(struct syncluster *sc,
187  const char *name,
188  struct clusterobj *cobj)
189 {
190  return pvsyncluster_addobj(sc, name, cobj);
191 }
192 
193 static inline int syncluster_delobj(struct syncluster *sc,
194  struct clusterobj *cobj)
195 {
196  return pvsyncluster_delobj(sc, cobj);
197 }
198 
199 static inline __must_check
200 int syncluster_findobj(struct syncluster *sc,
201  const char *name,
202  const struct timespec *timeout,
203  struct clusterobj **cobjp)
204 {
205  return pvsyncluster_findobj(sc, name, timeout, cobjp);
206 }
207 
208 #endif /* !CONFIG_XENO_PSHARED */
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif /* _COPPERPLATE_CLUSTER_H */