ia64/xen-unstable

view extras/mini-os/include/semaphore.h @ 10843:4f6d858ea570

[PCI] Per-device permissive flag (replaces global permissive flag).
Signed-off-by: Chris Bookholt <hap10@tycho.ncsc.mil>
author kfraser@localhost.localdomain
date Fri Jul 28 12:56:10 2006 +0100 (2006-07-28)
parents 7557f0b4098c
children 9e88db95ddc7
line source
1 #ifndef _SEMAPHORE_H_
2 #define _SEMAPHORE_H_
4 #include <wait.h>
5 #include <spinlock.h>
7 /*
8 * Implementation of semaphore in Mini-os is simple, because
9 * there are no preemptive threads, the atomicity is guaranteed.
10 */
12 struct semaphore
13 {
14 int count;
15 struct wait_queue_head wait;
16 };
18 /*
19 * the semaphore definition
20 */
21 struct rw_semaphore {
22 signed long count;
23 spinlock_t wait_lock;
24 struct list_head wait_list;
25 int debug;
26 };
28 #define __SEMAPHORE_INITIALIZER(name, n) \
29 { \
30 .count = n, \
31 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
32 }
34 #define __MUTEX_INITIALIZER(name) \
35 __SEMAPHORE_INITIALIZER(name,1)
37 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
38 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
40 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
42 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
44 static inline void init_MUTEX(struct semaphore *sem)
45 {
46 sem->count = 1;
47 init_waitqueue_head(&sem->wait);
48 }
50 static void inline down(struct semaphore *sem)
51 {
52 wait_event(sem->wait, sem->count > 0);
53 sem->count--;
54 }
56 static void inline up(struct semaphore *sem)
57 {
58 sem->count++;
59 wake_up(&sem->wait);
60 }
62 /* FIXME! Thre read/write semaphores are unimplemented! */
63 static inline void init_rwsem(struct rw_semaphore *sem)
64 {
65 sem->count = 1;
66 }
68 static inline void down_read(struct rw_semaphore *sem)
69 {
70 }
73 static inline void up_read(struct rw_semaphore *sem)
74 {
75 }
77 static inline void up_write(struct rw_semaphore *sem)
78 {
79 }
81 static inline void down_write(struct rw_semaphore *sem)
82 {
83 }
85 #endif /* _SEMAPHORE_H */