Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Add cycle_kernel_lock()

A number of driver functions are so obviously trivial that they do not need
the big kernel lock - at least not overtly. It turns out that the
acquisition of the BKL in driver open() functions can perform a sort of
poor-hacker's serialization function, delaying the open operation until the
driver is certain to have completed its initialization. Add a simple
cycle_kernel_lock() function for these cases to make it clear that there is
no need to *hold* the BKL, just to be sure that we can acquire it.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>

+13
+13
include/linux/smp_lock.h
··· 27 27 extern void __lockfunc lock_kernel(void) __acquires(kernel_lock); 28 28 extern void __lockfunc unlock_kernel(void) __releases(kernel_lock); 29 29 30 + /* 31 + * Various legacy drivers don't really need the BKL in a specific 32 + * function, but they *do* need to know that the BKL became available. 33 + * This function just avoids wrapping a bunch of lock/unlock pairs 34 + * around code which doesn't really need it. 35 + */ 36 + static inline void cycle_kernel_lock(void) 37 + { 38 + lock_kernel(); 39 + unlock_kernel(); 40 + } 41 + 30 42 #else 31 43 32 44 #define lock_kernel() do { } while(0) 33 45 #define unlock_kernel() do { } while(0) 34 46 #define release_kernel_lock(task) do { } while(0) 47 + #define cycle_kernel_lock() do { } while(0) 35 48 #define reacquire_kernel_lock(task) 0 36 49 #define kernel_locked() 1 37 50