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.

131 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. cmplock.h
  5. Abstract:
  6. Macros that hide the system calls used to do locking. Allows
  7. cm and reg code to run in a variety of environments.
  8. Note that there is a single lock (in particular, a mutex) which
  9. protects the entire registry.
  10. Author:
  11. Bryan M. Willman (bryanwi) 30-Oct-91
  12. Environment:
  13. Revision History:
  14. --*/
  15. //
  16. // Macros for kernel mode environment
  17. //
  18. extern KMUTEX CmpRegistryMutex;
  19. #if DBG
  20. extern LONG CmpRegistryLockLocked;
  21. #endif
  22. //
  23. // Test macro
  24. //
  25. #if DBG
  26. #define ASSERT_CM_LOCK_OWNED() \
  27. if ( (CmpRegistryMutex.OwnerThread != KeGetCurrentThread()) || \
  28. (CmpRegistryMutex.Header.SignalState >= 1) ) \
  29. { \
  30. ASSERT(FALSE); \
  31. }
  32. #else
  33. #define ASSERT_CM_LOCK_OWNED()
  34. #endif
  35. //
  36. // This set of macros serializes all access to the registry via
  37. // a single Mutex.
  38. //
  39. //
  40. // CMP_LOCK_REGISTRY(
  41. // NTSTATUS *pstatus,
  42. // PLARGE_INTEGER timeout
  43. // );
  44. //
  45. // Routine Description:
  46. //
  47. // Acquires the CmpRegistryMutex, with specified timeout, and
  48. // returns status.
  49. //
  50. // Arguments:
  51. //
  52. // pstatus - pointer to variable to receive status from wait call
  53. //
  54. // timeout - pointer to timeout value
  55. //
  56. #if DBG
  57. #define CMP_LOCK_REGISTRY(status, timeout) \
  58. { \
  59. status = KeWaitForSingleObject( \
  60. &CmpRegistryMutex, \
  61. Executive, \
  62. KernelMode, \
  63. FALSE, \
  64. timeout \
  65. ); \
  66. CmpRegistryLockLocked++; \
  67. }
  68. #else
  69. #define CMP_LOCK_REGISTRY(status, timeout) \
  70. { \
  71. status = KeWaitForSingleObject( \
  72. &CmpRegistryMutex, \
  73. Executive, \
  74. KernelMode, \
  75. FALSE, \
  76. timeout \
  77. ); \
  78. }
  79. #endif
  80. //
  81. // CMP_UNLOCK_REGISTRY(
  82. // );
  83. //
  84. // Routine Description:
  85. //
  86. // Releases the CmpRegistryMutex.
  87. //
  88. //
  89. #if DBG
  90. #define CMP_UNLOCK_REGISTRY() \
  91. { \
  92. ASSERT(CmpRegistryLockLocked > 0); \
  93. KeReleaseMutex(&CmpRegistryMutex, FALSE); \
  94. CmpRegistryLockLocked--; \
  95. }
  96. #else
  97. #define CMP_UNLOCK_REGISTRY() \
  98. { \
  99. KeReleaseMutex(&CmpRegistryMutex, FALSE); \
  100. }
  101. #endif
  102. //
  103. // Debugging asserts
  104. //
  105. #if DBG
  106. #define ASSERT_REGISTRY_LOCKED() ASSERT(CmpRegistryLockLocked > 0)
  107. #else
  108. #define ASSERT_REGISTRY_LOCKED()
  109. #endif