Xenomai  3.1
semobj.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 _COPPERPLATE_SEMOBJ_H
20 #define _COPPERPLATE_SEMOBJ_H
21 
22 #include <boilerplate/compiler.h>
23 #include <copperplate/reference.h>
24 
25 struct semobj_waitentry {
26  pid_t pid;
27  char name[32];
28 };
29 
30 #ifdef CONFIG_XENO_COBALT
31 
32 #include <semaphore.h>
33 
34 struct semobj_corespec {
35  sem_t sem;
36 };
37 
38 #else /* CONFIG_XENO_MERCURY */
39 
40 #include <copperplate/syncobj.h>
41 
42 struct semobj_corespec {
43  struct syncobj sobj;
44  int flags;
45  int value;
46 };
47 
48 #endif /* CONFIG_XENO_MERCURY */
49 
50 struct semobj {
51  struct semobj_corespec core;
52  fnref_type(void (*)(struct semobj *smobj)) finalizer;
53 };
54 
55 #define SEMOBJ_PRIO 0x1
56 #define SEMOBJ_PULSE 0x2
57 #define SEMOBJ_WARNDEL 0x4
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 int semobj_init(struct semobj *smobj,
64  int flags, int value,
65  fnref_type(void (*)(struct semobj *smobj)) finalizer);
66 
67 int semobj_destroy(struct semobj *smobj);
68 
69 void semobj_uninit(struct semobj *smobj);
70 
71 int semobj_post(struct semobj *smobj);
72 
73 int semobj_broadcast(struct semobj *smobj);
74 
75 int semobj_wait(struct semobj *smobj,
76  const struct timespec *timeout) __must_check;
77 
78 int semobj_getvalue(struct semobj *smobj, int *sval);
79 
80 int semobj_inquire(struct semobj *smobj, size_t waitsz,
81  struct semobj_waitentry *waitlist,
82  int *val_r);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif /* _COPPERPLATE_SEMOBJ_H */