This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / include / linux / smp_lock.h
1 #ifndef __LINUX_SMPLOCK_H
2 #define __LINUX_SMPLOCK_H
3
4 #include <linux/config.h>
5 #include <linux/sched.h>
6 #include <linux/spinlock.h>
7
8 #define BKL_DEBUG /* For testing for sleep_on() abuse */
9
10 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) || defined(BKL_DEBUG)
11
12 extern spinlock_t kernel_flag;
13
14 #define kernel_locked()         (current->lock_depth >= 0)
15
16 #define get_kernel_lock()       spin_lock(&kernel_flag)
17 #define put_kernel_lock()       spin_unlock(&kernel_flag)
18
19 /*
20  * Release global kernel lock.
21  */
22 static inline void release_kernel_lock(struct task_struct *task)
23 {
24         if (unlikely(task->lock_depth >= 0))
25                 put_kernel_lock();
26 }
27
28 /*
29  * Re-acquire the kernel lock
30  */
31 static inline void reacquire_kernel_lock(struct task_struct *task)
32 {
33         if (unlikely(task->lock_depth >= 0))
34                 get_kernel_lock();
35 }
36
37 /*
38  * Getting the big kernel lock.
39  *
40  * This cannot happen asynchronously,
41  * so we only need to worry about other
42  * CPU's.
43  */
44 static inline void lock_kernel(void)
45 {
46         int depth = current->lock_depth+1;
47         if (likely(!depth))
48                 get_kernel_lock();
49         current->lock_depth = depth;
50 }
51
52 static inline void unlock_kernel(void)
53 {
54         BUG_ON(current->lock_depth < 0);
55         if (likely(--current->lock_depth < 0))
56                 put_kernel_lock();
57 }
58
59 #else
60
61 #define lock_kernel()                           do { } while(0)
62 #define unlock_kernel()                         do { } while(0)
63 #define release_kernel_lock(task)               do { } while(0)
64 #define reacquire_kernel_lock(task)             do { } while(0)
65 #define kernel_locked()                         1
66
67 #endif /* CONFIG_SMP || CONFIG_PREEMPT */
68 #endif /* __LINUX_SMPLOCK_H */