0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __LINUX_SEMAPHORE_H
0009 #define __LINUX_SEMAPHORE_H
0010
0011 #include <linux/list.h>
0012 #include <linux/spinlock.h>
0013
0014
0015 struct semaphore {
0016 raw_spinlock_t lock;
0017 unsigned int count;
0018 struct list_head wait_list;
0019 };
0020
0021 #define __SEMAPHORE_INITIALIZER(name, n) \
0022 { \
0023 .lock = __RAW_SPIN_LOCK_UNLOCKED((name).lock), \
0024 .count = n, \
0025 .wait_list = LIST_HEAD_INIT((name).wait_list), \
0026 }
0027
0028 #define DEFINE_SEMAPHORE(name) \
0029 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
0030
0031 static inline void sema_init(struct semaphore *sem, int val)
0032 {
0033 static struct lock_class_key __key;
0034 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
0035 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
0036 }
0037
0038 extern void down(struct semaphore *sem);
0039 extern int __must_check down_interruptible(struct semaphore *sem);
0040 extern int __must_check down_killable(struct semaphore *sem);
0041 extern int __must_check down_trylock(struct semaphore *sem);
0042 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
0043 extern void up(struct semaphore *sem);
0044
0045 #endif