Luca's patch ported
[cbs-scheduler.git] / include / linux / semaphore.h
bloba55636d419d768e93f5ec144a3314c8d38031b82
1 /*
2 * Copyright (c) 2008 Intel Corporation
3 * Author: Matthew Wilcox <willy@linux.intel.com>
5 * Distributed under the terms of the GNU GPL, version 2
7 * Please see kernel/semaphore.c for documentation of these functions
8 */
9 #ifndef __LINUX_SEMAPHORE_H
10 #define __LINUX_SEMAPHORE_H
12 #ifndef CONFIG_PREEMPT_RT
13 # define compat_semaphore semaphore
14 #endif
16 # include <linux/list.h>
17 # include <linux/spinlock.h>
19 /* Please don't access any members of this structure directly */
20 struct compat_semaphore {
21 spinlock_t lock;
22 unsigned int count;
23 struct list_head wait_list;
26 #define __COMPAT_SEMAPHORE_INITIALIZER(name, n) \
27 { \
28 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
29 .count = n, \
30 .wait_list = LIST_HEAD_INIT((name).wait_list), \
33 #define __COMPAT_DECLARE_SEMAPHORE_GENERIC(name, count) \
34 struct compat_semaphore name = __COMPAT_SEMAPHORE_INITIALIZER(name, count)
36 #define COMPAT_DECLARE_MUTEX(name) __COMPAT_DECLARE_SEMAPHORE_GENERIC(name, 1)
37 static inline void compat_sema_init(struct compat_semaphore *sem, int val)
39 static struct lock_class_key __key;
40 *sem = (struct compat_semaphore) __COMPAT_SEMAPHORE_INITIALIZER(*sem, val);
42 spin_lock_init(&sem->lock);
43 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
46 #define compat_init_MUTEX(sem) compat_sema_init(sem, 1)
47 #define compat_init_MUTEX_LOCKED(sem) compat_sema_init(sem, 0)
49 extern void compat_down(struct compat_semaphore *sem);
50 extern int __must_check compat_down_interruptible(struct compat_semaphore *sem);
51 extern int __must_check compat_down_killable(struct compat_semaphore *sem);
52 extern int __must_check compat_down_trylock(struct compat_semaphore *sem);
53 extern int __must_check compat_down_timeout(struct compat_semaphore *sem, long jiffies);
54 extern void compat_up(struct compat_semaphore *sem);
56 #ifdef CONFIG_PREEMPT_RT
57 # include <linux/rt_lock.h>
58 #else
59 #define DECLARE_MUTEX COMPAT_DECLARE_MUTEX
61 static inline void sema_init(struct compat_semaphore *sem, int val)
63 compat_sema_init(sem, val);
65 static inline void init_MUTEX(struct compat_semaphore *sem)
67 compat_init_MUTEX(sem);
69 static inline void init_MUTEX_LOCKED(struct compat_semaphore *sem)
71 compat_init_MUTEX_LOCKED(sem);
73 static inline void down(struct compat_semaphore *sem)
75 compat_down(sem);
77 static inline int down_interruptible(struct compat_semaphore *sem)
79 return compat_down_interruptible(sem);
81 static inline int down_trylock(struct compat_semaphore *sem)
83 return compat_down_trylock(sem);
85 static inline int down_timeout(struct compat_semaphore *sem, long jiffies)
87 return compat_down_timeout(sem, jiffies);
90 static inline void up(struct compat_semaphore *sem)
92 compat_up(sem);
94 #endif /* CONFIG_PREEMPT_RT */
96 #endif /* __LINUX_SEMAPHORE_H */