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