Xenomai API  2.6.5
sem.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_SEM_H
23 #define _XENO_SEM_H
24 
25 #include <nucleus/synch.h>
26 #include <native/types.h>
27 
28 /* Creation flags. */
29 #define S_PRIO XNSYNCH_PRIO /* Pend by task priority order. */
30 #define S_FIFO XNSYNCH_FIFO /* Pend by FIFO order. */
31 #define S_PULSE 0x100 /* Apply pulse mode. */
32 
33 typedef struct rt_sem_info {
34 
35  unsigned long count; /* !< Current semaphore value. */
36 
37  int nwaiters; /* !< Number of pending tasks. */
38 
39  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
40 
41 } RT_SEM_INFO;
42 
43 typedef struct rt_sem_placeholder {
44  xnhandle_t opaque;
45 } RT_SEM_PLACEHOLDER;
46 
47 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP)
48 
49 #include <native/ppd.h>
50 
51 #define XENO_SEM_MAGIC 0x55550303
52 
53 typedef struct rt_sem {
54 
55  unsigned magic; /* !< Magic code - must be first */
56 
57  xnsynch_t synch_base; /* !< Base synchronization object. */
58 
59  unsigned long count; /* !< Current semaphore value. */
60 
61  int mode; /* !< Creation mode. */
62 
63  xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */
64 
65  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
66 
67 #ifdef CONFIG_XENO_OPT_PERVASIVE
68  pid_t cpid; /* !< Creator's pid. */
69 #endif /* CONFIG_XENO_OPT_PERVASIVE */
70 
71  xnholder_t rlink; /* !< Link in resource queue. */
72 
73 #define rlink2sem(ln) container_of(ln, RT_SEM, rlink)
74 
75  xnqueue_t *rqueue; /* !< Backpointer to resource queue. */
76 
77 } RT_SEM;
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 #ifdef CONFIG_XENO_OPT_NATIVE_SEM
84 
85 int __native_sem_pkg_init(void);
86 
87 void __native_sem_pkg_cleanup(void);
88 
89 static inline void __native_sem_flush_rq(xnqueue_t *rq)
90 {
91  xeno_flush_rq(RT_SEM, rq, sem);
92 }
93 
94 int rt_sem_p_inner(RT_SEM *sem,
95  xntmode_t timeout_mode, RTIME timeout);
96 
97 #else /* !CONFIG_XENO_OPT_NATIVE_SEM */
98 
99 #define __native_sem_pkg_init() ({ 0; })
100 #define __native_sem_pkg_cleanup() do { } while(0)
101 #define __native_sem_flush_rq(rq) do { } while(0)
102 
103 #endif /* !CONFIG_XENO_OPT_NATIVE_SEM */
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #else /* !(__KERNEL__ || __XENO_SIM__) */
110 
111 typedef RT_SEM_PLACEHOLDER RT_SEM;
112 
113 #ifdef __cplusplus
114 extern "C" {
115 #endif
116 
117 int rt_sem_bind(RT_SEM *sem,
118  const char *name,
119  RTIME timeout);
120 
121 static inline int rt_sem_unbind (RT_SEM *sem)
122 
123 {
124  sem->opaque = XN_NO_HANDLE;
125  return 0;
126 }
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* __KERNEL__ || __XENO_SIM__ */
133 
134 #ifdef __cplusplus
135 extern "C" {
136 #endif
137 
138 /* Public interface. */
139 
140 int rt_sem_create(RT_SEM *sem,
141  const char *name,
142  unsigned long icount,
143  int mode);
144 
145 int rt_sem_delete(RT_SEM *sem);
146 
147 int rt_sem_p(RT_SEM *sem,
148  RTIME timeout);
149 
150 int rt_sem_p_until(RT_SEM *sem,
151  RTIME timeout);
152 
153 int rt_sem_v(RT_SEM *sem);
154 
155 int rt_sem_broadcast(RT_SEM *sem);
156 
157 int rt_sem_inquire(RT_SEM *sem,
158  RT_SEM_INFO *info);
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif /* !_XENO_SEM_H */
int rt_sem_inquire(RT_SEM *sem, RT_SEM_INFO *info)
Inquire about a semaphore.
Definition: sem.c:81
int rt_sem_broadcast(RT_SEM *sem)
Broadcast a semaphore.
Definition: sem.c:76
int rt_sem_bind(RT_SEM *sem, const char *name, RTIME timeout)
Bind to a semaphore.
Definition: sem.c:32
int rt_sem_v(RT_SEM *sem)
Signal a semaphore.
Definition: sem.c:71
int rt_sem_p_until(RT_SEM *sem, RTIME timeout)
Pend on a semaphore (with absolute timeout date).
Definition: sem.c:57
int rt_sem_create(RT_SEM *sem, const char *name, unsigned long icount, int mode)
Create a counting semaphore.
Definition: sem.c:26
static int rt_sem_unbind(RT_SEM *sem)
Unbind from a semaphore.
Definition: sem.h:121
This file is part of the Xenomai project.
int rt_sem_p(RT_SEM *sem, RTIME timeout)
Pend on a semaphore.
Definition: sem.c:43
int rt_sem_delete(RT_SEM *sem)
Delete a semaphore.
Definition: sem.c:38
This file is part of the Xenomai project.