Xenomai API  2.6.5
semaphore.h
1 /*
2  * Copyright (C) 2005 Philippe Gerum <[email protected]>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef _XENO_POSIX_SEMAPHORE_H
20 #define _XENO_POSIX_SEMAPHORE_H
21 
22 #if defined(__KERNEL__) || defined(__XENO_SIM__)
23 
24 #include <nucleus/xenomai.h>
25 
26 #ifdef __KERNEL__
27 #include <linux/kernel.h>
28 #include <linux/fcntl.h>
29 #endif /* __KERNEL__ */
30 
31 #ifdef __XENO_SIM__
32 #include <posix_overrides.h>
33 #endif /* __XENO_SIM__ */
34 
35 #define SEM_VALUE_MAX (INT_MAX)
36 #define SEM_FAILED NULL
37 
38 #ifdef __KERNEL__
39 /* Copied from Linuxthreads semaphore.h. */
40 struct _sem_fastlock
41 {
42  long int __status;
43  int __spinlock;
44 };
45 
46 typedef struct
47 {
48  struct _sem_fastlock __sem_lock;
49  int __sem_value;
50  long __sem_waiting;
51 } sem_t;
52 #endif /* __KERNEL__ */
53 
54 #else /* !(__KERNEL__ || __XENO_SIM__) */
55 
56 #pragma GCC system_header
57 
58 #include <fcntl.h> /* For sem_open flags. */
59 #include_next <semaphore.h>
60 
61 #endif /* !(__KERNEL__ || __XENO_SIM__) */
62 
63 struct pse51_sem;
64 
65 union __xeno_sem {
66  sem_t native_sem;
67  struct __shadow_sem {
68  unsigned magic;
69  struct pse51_sem *sem;
70  } shadow_sem;
71 };
72 
73 #if defined(__KERNEL__) || defined(__XENO_SIM__)
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 #undef sem_init
80 #define sem_init pse51_sem_init
81 
82 int pse51_sem_init(sem_t *sem,
83  int pshared,
84  unsigned int value);
85 
86 int sem_destroy(sem_t *sem);
87 
88 int sem_post(sem_t *sem);
89 
90 int sem_trywait(sem_t *sem);
91 
92 int sem_wait(sem_t *sem);
93 
94 int sem_timedwait(sem_t *sem,
95  const struct timespec *abs_timeout);
96 
97 int sem_getvalue(sem_t *sem,
98  int *value);
99 
100 sem_t *sem_open(const char *name, int oflag, ...);
101 
102 int sem_close(sem_t *sem);
103 
104 int sem_unlink(const char *name);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #else /* !(__KERNEL__ || __XENO_SIM__) */
111 
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
116 int __real_sem_init(sem_t *sem,
117  int pshared,
118  unsigned value);
119 
120 int __real_sem_destroy(sem_t *sem);
121 
122 int __real_sem_post(sem_t *sem);
123 
124 int __real_sem_wait(sem_t *sem);
125 
126 int __real_sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
127 
128 int __real_sem_trywait(sem_t *sem);
129 
130 int __real_sem_getvalue(sem_t *sem, int *value);
131 
132 sem_t *__real_sem_open(const char *name, int oflags, ...);
133 
134 int __real_sem_close(sem_t *sem);
135 
136 int __real_sem_unlink(const char *name);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* !(__KERNEL__ || __XENO_SIM__) */
143 
144 #endif /* _XENO_POSIX_SEMAPHORE_H */
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
Attempt, during a bounded time, to lock a semaphore.
Definition: sem.c:677
int sem_close(sem_t *sem)
Close a named semaphore.
Definition: sem.c:389
int sem_wait(sem_t *sem)
Lock a semaphore.
Definition: sem.c:627
int sem_post(sem_t *sem)
Unlock a semaphore.
Definition: sem.c:723
int sem_trywait(sem_t *sem)
Attempt to lock a semaphore.
Definition: sem.c:537
int sem_unlink(const char *name)
Unlink a named semaphore.
Definition: sem.c:459
sem_t * sem_open(const char *name, int oflag,...)
Open a named semaphore.
Definition: sem.c:289
int sem_destroy(sem_t *sem)
Destroy an unnamed semaphore.
Definition: sem.c:214
int sem_getvalue(sem_t *sem, int *value)
Get the value of a semaphore.
Definition: sem.c:791