Xenomai  3.1
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 #include <xenomai/posix/process.h>
27 
28 struct cobalt_process;
29 struct filename;
30 
31 struct cobalt_sem {
32  unsigned int magic;
33  struct xnsynch synchbase;
34  struct cobalt_sem_state *state;
35  int flags;
36  unsigned int refs;
37  struct filename *pathname;
38  struct cobalt_resnode resnode;
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_nsem_reclaim(struct cobalt_process *process);
74 
75 struct cobalt_sem *
76 __cobalt_sem_init(const char *name, struct cobalt_sem_shadow *sem,
77  int flags, unsigned value);
78 
79 void __cobalt_sem_shadow_init(struct cobalt_sem *sem, __u32 magic,
80  struct cobalt_sem_shadow *sm);
81 
82 COBALT_SYSCALL_DECL(sem_init,
83  (struct cobalt_sem_shadow __user *u_sem,
84  int flags, unsigned value));
85 
86 COBALT_SYSCALL_DECL(sem_post,
87  (struct cobalt_sem_shadow __user *u_sem));
88 
89 COBALT_SYSCALL_DECL(sem_wait,
90  (struct cobalt_sem_shadow __user *u_sem));
91 
92 COBALT_SYSCALL_DECL(sem_timedwait,
93  (struct cobalt_sem_shadow __user *u_sem,
94  struct timespec __user *u_ts));
95 
96 COBALT_SYSCALL_DECL(sem_trywait,
97  (struct cobalt_sem_shadow __user *u_sem));
98 
99 COBALT_SYSCALL_DECL(sem_getvalue,
100  (struct cobalt_sem_shadow __user *u_sem,
101  int __user *u_sval));
102 
103 COBALT_SYSCALL_DECL(sem_destroy,
104  (struct cobalt_sem_shadow __user *u_sem));
105 
106 COBALT_SYSCALL_DECL(sem_open,
107  (struct cobalt_sem_shadow __user *__user *u_addrp,
108  const char __user *u_name,
109  int oflags, mode_t mode, unsigned int value));
110 
111 COBALT_SYSCALL_DECL(sem_close,
112  (struct cobalt_sem_shadow __user *usm));
113 
114 COBALT_SYSCALL_DECL(sem_unlink, (const char __user *u_name));
115 
116 COBALT_SYSCALL_DECL(sem_broadcast_np,
117  (struct cobalt_sem_shadow __user *u_sem));
118 
119 COBALT_SYSCALL_DECL(sem_inquire,
120  (struct cobalt_sem_shadow __user *u_sem,
121  struct cobalt_sem_info __user *u_info,
122  pid_t __user *u_waitlist,
123  size_t waitsz));
124 
125 void cobalt_sem_reclaim(struct cobalt_resnode *node,
126  spl_t s);
127 
128 #endif /* !_COBALT_POSIX_SEM_H */
int sem_wait(sem_t *sem)
Decrement a semaphore
Definition: semaphore.c:315
int sem_trywait(sem_t *sem)
Attempt to decrement a semaphore
Definition: semaphore.c:251
int sem_unlink(const char *name)
Unlink a named semaphore
Definition: semaphore.c:605
int sem_close(sem_t *sem)
Close a named semaphore
Definition: semaphore.c:557
int sem_destroy(sem_t *sem)
Destroy an unnamed semaphore
Definition: semaphore.c:141
int sem_init(sem_t *sem, int pshared, unsigned int value)
Initialize an unnamed semaphore.
Definition: semaphore.c:88
int sem_post(sem_t *sem)
Post a semaphore
Definition: semaphore.c:188
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
Attempt to decrement a semaphore with a time limit
Definition: semaphore.c:371