Xenomai  3.0-rc3
sem.h
1 /*
2  * Written by Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
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 #ifndef _COBALT_POSIX_SEM_H
19 #define _COBALT_POSIX_SEM_H
20 
21 #include <linux/kernel.h>
22 #include <linux/fcntl.h>
23 #include <cobalt/kernel/thread.h>
24 #include <cobalt/kernel/registry.h>
25 #include <xenomai/posix/syscall.h>
26 
27 struct cobalt_process;
28 
29 struct cobalt_sem {
30  unsigned int magic;
31  struct xnsynch synchbase;
33  struct list_head link;
34  struct cobalt_sem_state *state;
35  int flags;
36  struct cobalt_kqueues *owningq;
37  xnhandle_t handle;
38  unsigned int refs;
39 };
40 
41 /* Copied from Linuxthreads semaphore.h. */
42 struct _sem_fastlock
43 {
44  long int __status;
45  int __spinlock;
46 };
47 
48 typedef struct
49 {
50  struct _sem_fastlock __sem_lock;
51  int __sem_value;
52  long __sem_waiting;
53 } sem_t;
54 
55 #include <cobalt/uapi/sem.h>
56 
57 #define SEM_VALUE_MAX (INT_MAX)
58 #define SEM_FAILED NULL
59 #define SEM_NAMED 0x80000000
60 
61 struct cobalt_sem_shadow __user *
62 __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
63  const char __user *u_name,
64  int oflags, mode_t mode, unsigned int value);
65 
66 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
67  const void __user *u_ts,
68  int (*fetch_timeout)(struct timespec *ts,
69  const void __user *u_ts));
70 
71 int __cobalt_sem_destroy(xnhandle_t handle);
72 
73 void __cobalt_sem_unlink(xnhandle_t handle);
74 
75 void cobalt_sem_usems_cleanup(struct cobalt_process *cc);
76 
77 struct cobalt_sem *
78 __cobalt_sem_init(const char *name, struct cobalt_sem_shadow *sem,
79  int flags, unsigned value);
80 
81 COBALT_SYSCALL_DECL(sem_init,
82  (struct cobalt_sem_shadow __user *u_sem,
83  int flags, unsigned value));
84 
85 COBALT_SYSCALL_DECL(sem_post,
86  (struct cobalt_sem_shadow __user *u_sem));
87 
88 COBALT_SYSCALL_DECL(sem_wait,
89  (struct cobalt_sem_shadow __user *u_sem));
90 
91 COBALT_SYSCALL_DECL(sem_timedwait,
92  (struct cobalt_sem_shadow __user *u_sem,
93  struct timespec __user *u_ts));
94 
95 COBALT_SYSCALL_DECL(sem_trywait,
96  (struct cobalt_sem_shadow __user *u_sem));
97 
98 COBALT_SYSCALL_DECL(sem_getvalue,
99  (struct cobalt_sem_shadow __user *u_sem,
100  int __user *u_sval));
101 
102 COBALT_SYSCALL_DECL(sem_destroy,
103  (struct cobalt_sem_shadow __user *u_sem));
104 
105 COBALT_SYSCALL_DECL(sem_open,
106  (struct cobalt_sem_shadow __user *__user *u_addrp,
107  const char __user *u_name,
108  int oflags, mode_t mode, unsigned int value));
109 
110 COBALT_SYSCALL_DECL(sem_close,
111  (struct cobalt_sem_shadow __user *usm));
112 
113 COBALT_SYSCALL_DECL(sem_unlink, (const char __user *u_name));
114 
115 COBALT_SYSCALL_DECL(sem_broadcast_np,
116  (struct cobalt_sem_shadow __user *u_sem));
117 
118 COBALT_SYSCALL_DECL(sem_inquire,
119  (struct cobalt_sem_shadow __user *u_sem,
120  struct cobalt_sem_info __user *u_info,
121  pid_t __user *u_waitlist,
122  size_t waitsz));
123 
124 void cobalt_semq_cleanup(struct cobalt_kqueues *q);
125 
126 void cobalt_sem_pkg_init(void);
127 
128 void cobalt_sem_pkg_cleanup(void);
129 
130 #endif /* !_COBALT_POSIX_SEM_H */
int sem_wait(sem_t *sem)
Decrement a semaphore.
Definition: semaphore.c:299
int sem_trywait(sem_t *sem)
Attempt to decrement a semaphore.
Definition: semaphore.c:238
int sem_unlink(const char *name)
Unlink a named semaphore.
Definition: semaphore.c:576
int sem_close(sem_t *sem)
Close a named semaphore.
Definition: semaphore.c:531
int sem_destroy(sem_t *sem)
Destroy an unnamed semaphore.
Definition: semaphore.c:134
int sem_init(sem_t *sem, int pshared, unsigned int value)
Initialize an unnamed semaphore.
Definition: semaphore.c:84
int sem_post(sem_t *sem)
Post a semaphore.
Definition: semaphore.c:178
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
Attempt to decrement a semaphore with a time limit.
Definition: semaphore.c:352