smplock.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:1k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * <asm/smplock.h>
  3.  *
  4.  * i386 SMP lock implementation
  5.  */
  6. #include <linux/interrupt.h>
  7. #include <linux/spinlock.h>
  8. #include <linux/sched.h>
  9. #include <asm/current.h>
  10. extern spinlock_cacheline_t kernel_flag_cacheline;  
  11. #define kernel_flag kernel_flag_cacheline.lock      
  12. #define kernel_locked() spin_is_locked(&kernel_flag)
  13. /*
  14.  * Release global kernel lock and global interrupt lock
  15.  */
  16. #define release_kernel_lock(task, cpu) 
  17. do { 
  18. if (task->lock_depth >= 0) 
  19. spin_unlock(&kernel_flag); 
  20. release_irqlock(cpu); 
  21. __sti(); 
  22. } while (0)
  23. /*
  24.  * Re-acquire the kernel lock
  25.  */
  26. #define reacquire_kernel_lock(task) 
  27. do { 
  28. if (task->lock_depth >= 0) 
  29. spin_lock(&kernel_flag); 
  30. } while (0)
  31. /*
  32.  * Getting the big kernel lock.
  33.  *
  34.  * This cannot happen asynchronously,
  35.  * so we only need to worry about other
  36.  * CPU's.
  37.  */
  38. static __inline__ void lock_kernel(void)
  39. {
  40. #if 1
  41. if (!++current->lock_depth)
  42. spin_lock(&kernel_flag);
  43. #else
  44. __asm__ __volatile__(
  45. "incl %1nt"
  46. "jne 9f"
  47. spin_lock_string
  48. "n9:"
  49. :"=m" (__dummy_lock(&kernel_flag)),
  50.  "=m" (current->lock_depth));
  51. #endif
  52. }
  53. static __inline__ void unlock_kernel(void)
  54. {
  55. if (current->lock_depth < 0)
  56. out_of_line_bug();
  57. #if 1
  58. if (--current->lock_depth < 0)
  59. spin_unlock(&kernel_flag);
  60. #else
  61. __asm__ __volatile__(
  62. "decl %1nt"
  63. "jns 9fnt"
  64. spin_unlock_string
  65. "n9:"
  66. :"=m" (__dummy_lock(&kernel_flag)),
  67.  "=m" (current->lock_depth));
  68. #endif
  69. }