Xenomai  3.0.8
sem.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 #ifndef _XENOMAI_ALCHEMY_SEM_H
19 #define _XENOMAI_ALCHEMY_SEM_H
20 
21 #include <stdint.h>
22 #include <alchemy/timer.h>
23 
30 #define S_PRIO 0x1 /* Pend by task priority order. */
31 #define S_FIFO 0x0 /* Pend by FIFO order. */
32 #define S_PULSE 0x2 /* Enable pulse mode. */
33 
34 struct RT_SEM {
35  uintptr_t handle;
36 };
37 
38 typedef struct RT_SEM RT_SEM;
39 
47 struct RT_SEM_INFO {
51  unsigned long count;
55  int nwaiters;
59  char name[XNOBJECT_NAME_LEN];
60 };
61 
62 typedef struct RT_SEM_INFO RT_SEM_INFO;
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 int rt_sem_create(RT_SEM *sem,
69  const char *name,
70  unsigned long icount,
71  int mode);
72 
73 int rt_sem_delete(RT_SEM *sem);
74 
75 int rt_sem_p_timed(RT_SEM *sem,
76  const struct timespec *abs_timeout);
77 
78 static inline int rt_sem_p_until(RT_SEM *sem, RTIME timeout)
79 {
80  struct timespec ts;
81  return rt_sem_p_timed(sem, alchemy_abs_timeout(timeout, &ts));
82 }
83 
84 static inline int rt_sem_p(RT_SEM *sem, RTIME timeout)
85 {
86  struct timespec ts;
87  return rt_sem_p_timed(sem, alchemy_rel_timeout(timeout, &ts));
88 }
89 
90 int rt_sem_v(RT_SEM *sem);
91 
92 int rt_sem_broadcast(RT_SEM *sem);
93 
94 int rt_sem_inquire(RT_SEM *sem,
95  RT_SEM_INFO *info);
96 
97 int rt_sem_bind(RT_SEM *sem,
98  const char *name, RTIME timeout);
99 
100 int rt_sem_unbind(RT_SEM *sem);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
108 #endif /* _XENOMAI_ALCHEMY_SEM_H */
int rt_sem_v(RT_SEM *sem)
Signal a semaphore.
Definition: sem.c:410
static int rt_sem_p(RT_SEM *sem, RTIME timeout)
Pend on a semaphore (with relative scalar timeout).
Definition: sem.h:84
int rt_sem_broadcast(RT_SEM *sem)
Broadcast a semaphore.
Definition: sem.c:445
int nwaiters
Number of tasks waiting on the semaphore.
Definition: sem.h:55
Semaphore status descriptor.
Definition: sem.h:47
unsigned long count
Current semaphore value.
Definition: sem.h:51
int rt_sem_create(RT_SEM *sem, const char *name, unsigned long icount, int mode)
Create a counting semaphore.
Definition: sem.c:178
static int rt_sem_p_until(RT_SEM *sem, RTIME timeout)
Pend on a semaphore (with absolute scalar timeout).
Definition: sem.h:78
int rt_sem_unbind(RT_SEM *sem)
Unbind from a semaphore.
Definition: sem.c:574
int rt_sem_bind(RT_SEM *sem, const char *name, RTIME timeout)
Bind to a semaphore.
Definition: sem.c:552
int rt_sem_inquire(RT_SEM *sem, RT_SEM_INFO *info)
Query semaphore status.
Definition: sem.c:484
char name[XNOBJECT_NAME_LEN]
Name of semaphore.
Definition: sem.h:59
int rt_sem_p_timed(RT_SEM *sem, const struct timespec *abs_timeout)
Pend on a semaphore.
Definition: sem.c:373
int rt_sem_delete(RT_SEM *sem)
Delete a semaphore.
Definition: sem.c:259