Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_SMPLOCK_H |
| 2 | #define __LINUX_SMPLOCK_H |
| 3 | |
Al Viro | f037360 | 2005-11-13 16:06:57 -0800 | [diff] [blame] | 4 | #ifdef CONFIG_LOCK_KERNEL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | extern int __lockfunc __reacquire_kernel_lock(void); |
| 8 | extern void __lockfunc __release_kernel_lock(void); |
| 9 | |
| 10 | /* |
| 11 | * Release/re-acquire global kernel lock for the scheduler |
| 12 | */ |
| 13 | #define release_kernel_lock(tsk) do { \ |
| 14 | if (unlikely((tsk)->lock_depth >= 0)) \ |
| 15 | __release_kernel_lock(); \ |
| 16 | } while (0) |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | static inline int reacquire_kernel_lock(struct task_struct *task) |
| 19 | { |
| 20 | if (unlikely(task->lock_depth >= 0)) |
Ingo Molnar | 6478d88 | 2008-01-25 21:08:33 +0100 | [diff] [blame] | 21 | return __reacquire_kernel_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | return 0; |
| 23 | } |
| 24 | |
Frederic Weisbecker | 925936e | 2009-09-28 17:12:49 +0200 | [diff] [blame] | 25 | extern void __lockfunc |
| 26 | _lock_kernel(const char *func, const char *file, int line) |
| 27 | __acquires(kernel_lock); |
Frederic Weisbecker | 96a2c46 | 2009-08-01 01:34:24 +0200 | [diff] [blame] | 28 | |
Frederic Weisbecker | 925936e | 2009-09-28 17:12:49 +0200 | [diff] [blame] | 29 | extern void __lockfunc |
| 30 | _unlock_kernel(const char *func, const char *file, int line) |
| 31 | __releases(kernel_lock); |
Frederic Weisbecker | 96a2c46 | 2009-08-01 01:34:24 +0200 | [diff] [blame] | 32 | |
Frederic Weisbecker | 925936e | 2009-09-28 17:12:49 +0200 | [diff] [blame] | 33 | #define lock_kernel() do { \ |
| 34 | _lock_kernel(__func__, __FILE__, __LINE__); \ |
| 35 | } while (0) |
| 36 | |
| 37 | #define unlock_kernel() do { \ |
| 38 | _unlock_kernel(__func__, __FILE__, __LINE__); \ |
| 39 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Jonathan Corbet | 0b28067 | 2008-05-18 14:27:41 -0600 | [diff] [blame] | 41 | /* |
| 42 | * Various legacy drivers don't really need the BKL in a specific |
| 43 | * function, but they *do* need to know that the BKL became available. |
| 44 | * This function just avoids wrapping a bunch of lock/unlock pairs |
| 45 | * around code which doesn't really need it. |
| 46 | */ |
| 47 | static inline void cycle_kernel_lock(void) |
| 48 | { |
| 49 | lock_kernel(); |
| 50 | unlock_kernel(); |
| 51 | } |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #else |
| 54 | |
Arnd Bergmann | 6de5bd1 | 2010-09-11 18:00:57 +0200 | [diff] [blame] | 55 | #ifdef CONFIG_BKL /* provoke build bug if not set */ |
Frederic Weisbecker | 925936e | 2009-09-28 17:12:49 +0200 | [diff] [blame] | 56 | #define lock_kernel() |
| 57 | #define unlock_kernel() |
Jonathan Corbet | 0b28067 | 2008-05-18 14:27:41 -0600 | [diff] [blame] | 58 | #define cycle_kernel_lock() do { } while(0) |
Arnd Bergmann | 6de5bd1 | 2010-09-11 18:00:57 +0200 | [diff] [blame] | 59 | #endif /* CONFIG_BKL */ |
| 60 | |
| 61 | #define release_kernel_lock(task) do { } while(0) |
| 62 | #define reacquire_kernel_lock(task) 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #endif /* CONFIG_LOCK_KERNEL */ |
| 65 | #endif /* __LINUX_SMPLOCK_H */ |