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.

161 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. crtsect.hxx
  6. Abstract:
  7. Critical Section class header
  8. Author:
  9. Steve Kiraly (SteveKi) 30-March-1997
  10. Revision History:
  11. Mark Lawrence (MLawrenc) 07-March-2000
  12. Copied this class from the Debug Library. Added debug support for
  13. checking thread ownership.
  14. NOTE: All of the methods of this class are const.... the reason for
  15. this is that we want a class to be able to expose const methods that
  16. nonetheless can call critical sections. This prevents someone else
  17. modifying the data in the class while you are traversing lists etc.
  18. --*/
  19. #ifndef _CORE_CRTSECT_HXX_
  20. #define _CORE_CRTSECT_HXX_
  21. namespace NCoreLibrary {
  22. class TCriticalSection
  23. {
  24. SIGNATURE('crit');
  25. public:
  26. TCriticalSection(
  27. IN BOOL bPrealloc = TRUE
  28. );
  29. ~TCriticalSection(
  30. VOID
  31. );
  32. HRESULT
  33. IsValid(
  34. VOID
  35. ) const;
  36. VOID
  37. CheckInCS(
  38. VOID
  39. ) const;
  40. VOID
  41. CheckOutOfCS(
  42. VOID
  43. ) const;
  44. HRESULT
  45. Enter(
  46. VOID
  47. ) const;
  48. HRESULT
  49. Leave(
  50. VOID
  51. ) const;
  52. HRESULT
  53. GetOwningThreadId(
  54. OUT DWORD *pdwThreadId
  55. );
  56. //
  57. // Helper class to enter and exit the critical section
  58. // using the constructor and destructor idiom.
  59. //
  60. class TLock
  61. {
  62. public:
  63. TLock(
  64. IN const TCriticalSection &CriticalSection
  65. );
  66. ~TLock(
  67. VOID
  68. );
  69. private:
  70. //
  71. // Copying and assignment are not defined.
  72. //
  73. NO_COPY(TLock);
  74. const TCriticalSection &m_CriticalSection;
  75. HRESULT m_hr;
  76. };
  77. //
  78. // Helper class to exit and enter the critical section
  79. // using the constructor and destructor idiom.
  80. //
  81. class TUnLock
  82. {
  83. public:
  84. TUnLock(
  85. IN const TCriticalSection &CriticalSection
  86. );
  87. ~TUnLock(
  88. VOID
  89. );
  90. private:
  91. //
  92. // Copying and assignment are not defined.
  93. //
  94. NO_COPY(TUnLock);
  95. const TCriticalSection &m_CriticalSection;
  96. HRESULT m_hr;
  97. };
  98. private:
  99. //
  100. // Copying and assignment are not defined.
  101. //
  102. NO_COPY(TCriticalSection);
  103. HRESULT
  104. Initialize(
  105. IN BOOL bPrealloc = TRUE
  106. );
  107. VOID
  108. Release(
  109. VOID
  110. );
  111. CRITICAL_SECTION m_CriticalSection;
  112. DWORD m_dwOwnerId;
  113. UINT m_uEnterCount;
  114. HRESULT m_hr;
  115. };
  116. }
  117. #endif