Xenomai  3.0.5
internal.h
1 /*
2  * Copyright (C) 2011 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 _ALCHEMY_INTERNAL_H
20 #define _ALCHEMY_INTERNAL_H
21 
22 #include "boilerplate/ancillaries.h"
23 #include "timer.h"
24 
25 #define DEFINE_SYNC_LOOKUP(__name, __dsctype) \
26 static inline struct alchemy_ ## __name * \
27 get_alchemy_ ## __name(__dsctype *desc, \
28  struct syncstate *syns, int *err_r) \
29 { \
30  struct alchemy_ ## __name *cb; \
31  \
32  if (bad_pointer(desc)) { \
33  *err_r = -EINVAL; \
34  return NULL; \
35  } \
36  \
37  cb = mainheap_deref(desc->handle, struct alchemy_ ## __name); \
38  if (bad_pointer(cb)) { \
39  *err_r = -EINVAL; \
40  return NULL; \
41  } \
42  \
43  if (syncobj_lock(&cb->sobj, syns) || \
44  cb->magic != __name ## _magic) { \
45  *err_r = -EINVAL; \
46  return NULL; \
47  } \
48  \
49  return cb; \
50 } \
51  \
52 static inline \
53 void put_alchemy_ ## __name(struct alchemy_ ## __name *cb, \
54  struct syncstate *syns) \
55 { \
56  syncobj_unlock(&cb->sobj, syns); \
57 }
58 
59 #define __DEFINE_LOOKUP(__scope, __name, __dsctype) \
60 __scope struct alchemy_ ## __name * \
61 find_alchemy_ ## __name(__dsctype *desc, int *err_r) \
62 { \
63  struct alchemy_ ## __name *cb; \
64  \
65  if (bad_pointer(desc)) { \
66  *err_r = -EINVAL; \
67  return NULL; \
68  } \
69  \
70  cb = mainheap_deref(desc->handle, struct alchemy_ ## __name); \
71  if (bad_pointer(cb) || cb->magic != __name ## _magic) { \
72  *err_r = -EINVAL; \
73  return NULL; \
74  } \
75  \
76  return cb; \
77 } \
78 
79 #define DEFINE_LOOKUP_PRIVATE(__name, __dsctype) \
80  __DEFINE_LOOKUP(static inline, __name, __dsctype)
81 
82 #define DEFINE_LOOKUP(__name, __dsctype) \
83  __DEFINE_LOOKUP(, __name, __dsctype)
84 
85 struct syncluster;
86 
87 int alchemy_bind_object(const char *name, struct syncluster *sc,
88  RTIME timeout,
89  int offset,
90  uintptr_t *handle);
91 
92 #endif /* !_ALCHEMY_INTERNAL_H */