1 
2 #ifndef __SEMAPHORE_H__
3 #define __SEMAPHORE_H__
4 
5 #include <sys/queue.h>
6 #include <sys/spinlock.h>
7 
8 #define SEMAPHORE_NAMELEN   32
9 
10 struct Thread;
11 
12 typedef struct Semaphore
13 {
14     Spinlock					lock;
15     char					name[SEMAPHORE_NAMELEN];
16     int						count;
17     TAILQ_HEAD(SemaThreadQueue,Thread)		waiters;
18     LIST_ENTRY(Semaphore)			semaphoreList;
19 } Semaphore;
20 
21 void Semaphore_Init(Semaphore *sema, int count, const char *name);
22 void Semaphore_Destroy(Semaphore *sema);
23 void Semaphore_Acquire(Semaphore *sema);
24 // bool TimedAcquire(Semaphore *sema, uint64_t timeout);
25 void Semaphore_Release(Semaphore *sema);
26 bool Semaphore_TryAcquire(Semaphore *sema);
27 
28 #endif /* __SEMAPHORE_H__ */
29 
30