| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | #ifdef CONFIG_LOCK_KERNEL | 
|  | 9 |  | 
|  | 10 | #define kernel_locked()		(current->lock_depth >= 0) | 
|  | 11 |  | 
|  | 12 | extern int __lockfunc __reacquire_kernel_lock(void); | 
|  | 13 | extern void __lockfunc __release_kernel_lock(void); | 
|  | 14 |  | 
|  | 15 | /* | 
|  | 16 | * Release/re-acquire global kernel lock for the scheduler | 
|  | 17 | */ | 
|  | 18 | #define release_kernel_lock(tsk) do { 		\ | 
|  | 19 | if (unlikely((tsk)->lock_depth >= 0))	\ | 
|  | 20 | __release_kernel_lock();	\ | 
|  | 21 | } while (0) | 
|  | 22 |  | 
|  | 23 | /* | 
|  | 24 | * Non-SMP kernels will never block on the kernel lock, | 
|  | 25 | * so we are better off returning a constant zero from | 
|  | 26 | * reacquire_kernel_lock() so that the compiler can see | 
|  | 27 | * it at compile-time. | 
|  | 28 | */ | 
|  | 29 | #if defined(CONFIG_SMP) && !defined(CONFIG_PREEMPT_BKL) | 
|  | 30 | # define return_value_on_smp return | 
|  | 31 | #else | 
|  | 32 | # define return_value_on_smp | 
|  | 33 | #endif | 
|  | 34 |  | 
|  | 35 | static inline int reacquire_kernel_lock(struct task_struct *task) | 
|  | 36 | { | 
|  | 37 | if (unlikely(task->lock_depth >= 0)) | 
|  | 38 | return_value_on_smp __reacquire_kernel_lock(); | 
|  | 39 | return 0; | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | extern void __lockfunc lock_kernel(void)	__acquires(kernel_lock); | 
|  | 43 | extern void __lockfunc unlock_kernel(void)	__releases(kernel_lock); | 
|  | 44 |  | 
|  | 45 | #else | 
|  | 46 |  | 
|  | 47 | #define lock_kernel()				do { } while(0) | 
|  | 48 | #define unlock_kernel()				do { } while(0) | 
|  | 49 | #define release_kernel_lock(task)		do { } while(0) | 
|  | 50 | #define reacquire_kernel_lock(task)		0 | 
|  | 51 | #define kernel_locked()				1 | 
|  | 52 |  | 
|  | 53 | #endif /* CONFIG_LOCK_KERNEL */ | 
|  | 54 | #endif /* __LINUX_SMPLOCK_H */ |