smp_lock.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef __LINUX_SMPLOCK_H
  2. #define __LINUX_SMPLOCK_H
  3. #ifdef CONFIG_LOCK_KERNEL
  4. #include <linux/sched.h>
  5. #define kernel_locked() (current->lock_depth >= 0)
  6. extern int __lockfunc __reacquire_kernel_lock(void);
  7. extern void __lockfunc __release_kernel_lock(void);
  8. /*
  9. * Release/re-acquire global kernel lock for the scheduler
  10. */
  11. #define release_kernel_lock(tsk) do { \
  12. if (unlikely((tsk)->lock_depth >= 0)) \
  13. __release_kernel_lock(); \
  14. } while (0)
  15. static inline int reacquire_kernel_lock(struct task_struct *task)
  16. {
  17. if (unlikely(task->lock_depth >= 0))
  18. return __reacquire_kernel_lock();
  19. return 0;
  20. }
  21. extern void __lockfunc
  22. _lock_kernel(const char *func, const char *file, int line)
  23. __acquires(kernel_lock);
  24. extern void __lockfunc
  25. _unlock_kernel(const char *func, const char *file, int line)
  26. __releases(kernel_lock);
  27. #define lock_kernel() do { \
  28. _lock_kernel(__func__, __FILE__, __LINE__); \
  29. } while (0)
  30. #define unlock_kernel() do { \
  31. _unlock_kernel(__func__, __FILE__, __LINE__); \
  32. } while (0)
  33. /*
  34. * Various legacy drivers don't really need the BKL in a specific
  35. * function, but they *do* need to know that the BKL became available.
  36. * This function just avoids wrapping a bunch of lock/unlock pairs
  37. * around code which doesn't really need it.
  38. */
  39. static inline void cycle_kernel_lock(void)
  40. {
  41. lock_kernel();
  42. unlock_kernel();
  43. }
  44. #else
  45. #ifdef CONFIG_BKL /* provoke build bug if not set */
  46. #define lock_kernel()
  47. #define unlock_kernel()
  48. #define cycle_kernel_lock() do { } while(0)
  49. #define kernel_locked() 1
  50. #endif /* CONFIG_BKL */
  51. #define release_kernel_lock(task) do { } while(0)
  52. #define reacquire_kernel_lock(task) 0
  53. #endif /* CONFIG_LOCK_KERNEL */
  54. #endif /* __LINUX_SMPLOCK_H */