1 #ifndef _PPC_SEMAPHORE_H
2 #define _PPC_SEMAPHORE_H
5 * Swiped from asm-sparc/semaphore.h and modified
6 * -- Cort (cort@cs.nmt.edu)
11 #include <asm/atomic.h>
12 #include <linux/wait.h>
17 wait_queue_head_t wait
;
24 # define __SEM_DEBUG_INIT(name) \
25 , (long)&(name).__magic
27 # define __SEM_DEBUG_INIT(name)
30 #define __SEMAPHORE_INITIALIZER(name,count) \
31 { ATOMIC_INIT(count), ATOMIC_INIT(0), __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
32 __SEM_DEBUG_INIT(name) }
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)
41 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
43 extern inline void sema_init (struct semaphore
*sem
, int val
)
45 atomic_set(&sem
->count
, val
);
46 atomic_set(&sem
->waking
, 0);
47 init_waitqueue_head(&sem
->wait
);
49 sem
->__magic
= (long)&sem
->__magic
;
53 static inline void init_MUTEX (struct semaphore
*sem
)
58 static inline void init_MUTEX_LOCKED (struct semaphore
*sem
)
63 extern void __down(struct semaphore
* sem
);
64 extern int __down_interruptible(struct semaphore
* sem
);
65 extern int __down_trylock(struct semaphore
* sem
);
66 extern void __up(struct semaphore
* sem
);
68 extern inline void down(struct semaphore
* sem
)
70 if (atomic_dec_return(&sem
->count
) >= 0)
76 extern inline int down_interruptible(struct semaphore
* sem
)
80 if (atomic_dec_return(&sem
->count
) >= 0)
83 ret
= __down_interruptible(sem
);
87 extern inline int down_trylock(struct semaphore
* sem
)
91 if (atomic_dec_return(&sem
->count
) >= 0)
94 ret
= __down_trylock(sem
);
98 extern inline void up(struct semaphore
* sem
)
101 if (atomic_inc_return(&sem
->count
) <= 0)
105 #endif /* __KERNEL__ */
107 #endif /* !(_PPC_SEMAPHORE_H) */