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