Semi-decennial update. 50% code inflation.
[cbaos.git] / include / sem.h
blob8a8f91474c9eb41e19cf73e03fefca5db02e9e5d
1 #ifndef _SEM_H_
2 #define _SEM_H_
4 #include <sched.h>
5 #include <lock.h>
7 struct sem {
8 volatile int count;
9 struct list tasks; /* tasks waiting on semaphore */
10 struct lock lock;
13 #define SEM_DECLARE_INIT(sname, scount) \
14 struct sem sname = { \
15 .count = scount, \
16 .tasks = LIST_INIT(sname.tasks), \
17 .lock = LOCK_INIT, \
20 void sem_init(struct sem *sem, int count);
21 __attribute__ ((warn_unused_result)) int down(struct sem *sem, u32 timeout);
22 void up(struct sem *sem);
25 struct mutex {
26 volatile int locked;
27 struct list tasks; /* tasks waiting on mutexaphore */
28 struct lock lock;
31 void mutex_init(struct mutex *mutex, int count);
32 __attribute__ ((warn_unused_result)) int mutex_down(struct mutex *mutex, u32 timeout);
33 __attribute__ ((warn_unused_result)) int mutex_downtry(struct mutex *mutex);
34 void mutex_up(struct mutex *mutex);
36 #endif