xref: /minix3/minix/include/ddekit/semaphore.h (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #ifndef _DDEKIT_SEMAPHORE_H
2*433d6423SLionel Sambuc #define _DDEKIT_SEMAPHORE_H
3*433d6423SLionel Sambuc 
4*433d6423SLionel Sambuc #include <ddekit/ddekit.h>
5*433d6423SLionel Sambuc 
6*433d6423SLionel Sambuc 
7*433d6423SLionel Sambuc /** \defgroup DDEKit_synchronization */
8*433d6423SLionel Sambuc 
9*433d6423SLionel Sambuc struct ddekit_sem;
10*433d6423SLionel Sambuc typedef struct ddekit_sem ddekit_sem_t;
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc /** Initialize DDEKit semaphore.
13*433d6423SLionel Sambuc  *
14*433d6423SLionel Sambuc  * \ingroup DDEKit_synchronization
15*433d6423SLionel Sambuc  *
16*433d6423SLionel Sambuc  * \param value  initial semaphore counter
17*433d6423SLionel Sambuc  */
18*433d6423SLionel Sambuc ddekit_sem_t *ddekit_sem_init(int value);
19*433d6423SLionel Sambuc 
20*433d6423SLionel Sambuc /** Uninitialize semaphore.
21*433d6423SLionel Sambuc  *
22*433d6423SLionel Sambuc  * \ingroup DDEKit_synchronization
23*433d6423SLionel Sambuc  */
24*433d6423SLionel Sambuc void ddekit_sem_deinit(ddekit_sem_t *sem);
25*433d6423SLionel Sambuc 
26*433d6423SLionel Sambuc /** Semaphore down method. */
27*433d6423SLionel Sambuc void ddekit_sem_down(ddekit_sem_t *sem);
28*433d6423SLionel Sambuc 
29*433d6423SLionel Sambuc /** Semaphore down method, non-blocking.
30*433d6423SLionel Sambuc  *
31*433d6423SLionel Sambuc  * \ingroup DDEKit_synchronization
32*433d6423SLionel Sambuc  *
33*433d6423SLionel Sambuc  * \return 0   success
34*433d6423SLionel Sambuc  * \return !=0 would block
35*433d6423SLionel Sambuc  */
36*433d6423SLionel Sambuc int ddekit_sem_down_try(ddekit_sem_t *sem);
37*433d6423SLionel Sambuc 
38*433d6423SLionel Sambuc /** Semaphore down with timeout.
39*433d6423SLionel Sambuc  *
40*433d6423SLionel Sambuc  * \ingroup DDEKit_synchronization
41*433d6423SLionel Sambuc  *
42*433d6423SLionel Sambuc  * \return 0   success
43*433d6423SLionel Sambuc  * \return !=0 would block
44*433d6423SLionel Sambuc  */
45*433d6423SLionel Sambuc int ddekit_sem_down_timed(ddekit_sem_t *sem, int timo);
46*433d6423SLionel Sambuc 
47*433d6423SLionel Sambuc /** Semaphore up method.
48*433d6423SLionel Sambuc  *
49*433d6423SLionel Sambuc  * \ingroup DDEKit_synchronization
50*433d6423SLionel Sambuc  */
51*433d6423SLionel Sambuc void ddekit_sem_up(ddekit_sem_t *sem);
52*433d6423SLionel Sambuc 
53*433d6423SLionel Sambuc #endif
54