1 /*
2  * <asm/smplock.h>
3  *
4  * Default SMP lock implementation
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11 #include <linux/interrupt.h>
12 #include <linux/spinlock.h>
13 #include <asm/current.h>
14 
15 extern spinlock_t kernel_flag;
16 
17 #define kernel_locked()		spin_is_locked(&kernel_flag)
18 
19 /*
20  * Release global kernel lock and global interrupt lock
21  */
22 #define release_kernel_lock(task, cpu) \
23 do { \
24 	if (task->lock_depth >= 0) \
25 		spin_unlock(&kernel_flag); \
26 	release_irqlock(cpu); \
27 	__sti(); \
28 } while (0)
29 
30 /*
31  * Re-acquire the kernel lock
32  */
33 #define reacquire_kernel_lock(task) \
34 do { \
35 	if (task->lock_depth >= 0) \
36 		spin_lock(&kernel_flag); \
37 } while (0)
38 
39 
40 /*
41  * Getting the big kernel lock.
42  *
43  * This cannot happen asynchronously,
44  * so we only need to worry about other
45  * CPU's.
46  */
lock_kernel(void)47 static inline void lock_kernel(void)
48 {
49 	if (!++current->lock_depth)
50 		spin_lock(&kernel_flag);
51 }
52 
unlock_kernel(void)53 static inline void unlock_kernel(void)
54 {
55 	if (--current->lock_depth < 0)
56 		spin_unlock(&kernel_flag);
57 }
58