Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.3 KiB

  1. #ifndef _AUTOLOCK_HPP_
  2. #define _AUTOLOCK_HPP_
  3. // Ruler
  4. // 1 2 3 4 5 6 7 8
  5. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  6. /********************************************************************/
  7. /* */
  8. /* The standard layout. */
  9. /* */
  10. /* The standard layout for 'hpp' files for this code is as */
  11. /* follows: */
  12. /* */
  13. /* 1. Include files. */
  14. /* 2. Constants exported from the class. */
  15. /* 3. Data structures exported from the class. */
  16. /* 4. Forward references to other data structures. */
  17. /* 5. Class specifications (including inline functions). */
  18. /* 6. Additional large inline functions. */
  19. /* */
  20. /* Any portion that is not required is simply omitted. */
  21. /* */
  22. /********************************************************************/
  23. #include "Global.hpp"
  24. #include "Sharelock.hpp"
  25. #include "Spinlock.hpp"
  26. /********************************************************************/
  27. /* */
  28. /* Automatic sharelock control. */
  29. /* */
  30. /* We can simplify quite a bit of code using this class when we */
  31. /* only need to hold a share lock for the duration of a block */
  32. /* or a function. */
  33. /* */
  34. /********************************************************************/
  35. class AUTO_EXCLUSIVE_LOCK
  36. {
  37. //
  38. // Private data.
  39. //
  40. SHARELOCK *Sharelock;
  41. public:
  42. //
  43. // Public inline functions.
  44. //
  45. AUTO_EXCLUSIVE_LOCK( SHARELOCK *NewSharelock,SBIT32 Sleep = INFINITE )
  46. { (Sharelock = NewSharelock) -> ClaimExclusiveLock( Sleep ); }
  47. ~AUTO_EXCLUSIVE_LOCK( VOID )
  48. { Sharelock -> ReleaseExclusiveLock(); }
  49. private:
  50. //
  51. // Disabled operations.
  52. //
  53. AUTO_EXCLUSIVE_LOCK( CONST AUTO_EXCLUSIVE_LOCK & Copy );
  54. VOID operator=( CONST AUTO_EXCLUSIVE_LOCK & Copy );
  55. };
  56. /********************************************************************/
  57. /* */
  58. /* Automatic sharelock control. */
  59. /* */
  60. /* We can simplify quite a bit of code using this class when we */
  61. /* only need to hold a share lock for the duration of a block */
  62. /* or a function. */
  63. /* */
  64. /********************************************************************/
  65. class AUTO_SHARE_LOCK
  66. {
  67. //
  68. // Private data.
  69. //
  70. SHARELOCK *Sharelock;
  71. public:
  72. //
  73. // Public inline functions.
  74. //
  75. AUTO_SHARE_LOCK( SHARELOCK *NewSharelock,SBIT32 Sleep = INFINITE )
  76. { (Sharelock = NewSharelock) -> ClaimShareLock( Sleep ); }
  77. ~AUTO_SHARE_LOCK( VOID )
  78. { Sharelock -> ReleaseShareLock(); }
  79. private:
  80. //
  81. // Disabled operations.
  82. //
  83. AUTO_SHARE_LOCK( CONST AUTO_SHARE_LOCK & Copy );
  84. VOID operator=( CONST AUTO_SHARE_LOCK & Copy );
  85. };
  86. /********************************************************************/
  87. /* */
  88. /* Automatic spinlock control. */
  89. /* */
  90. /* We can simplify quite a bit of code using this class when we */
  91. /* only need to hold a spin lock for the duration of a block */
  92. /* or a function. */
  93. /* */
  94. /********************************************************************/
  95. class AUTO_SPIN_LOCK
  96. {
  97. //
  98. // Private data.
  99. //
  100. SPINLOCK *Spinlock;
  101. public:
  102. //
  103. // Public inline functions.
  104. //
  105. AUTO_SPIN_LOCK( SPINLOCK *NewSpinlock,SBIT32 Sleep = INFINITE )
  106. { (Spinlock = NewSpinlock) -> ClaimLock( Sleep ); }
  107. ~AUTO_SPIN_LOCK( VOID )
  108. { Spinlock -> ReleaseLock(); }
  109. private:
  110. //
  111. // Disabled operations.
  112. //
  113. AUTO_SPIN_LOCK( CONST AUTO_SPIN_LOCK & Copy );
  114. VOID operator=( CONST AUTO_SPIN_LOCK & Copy );
  115. };
  116. #endif