Source code of Windows XP (NT5)
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.

126 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgcs.cxx
  6. Abstract:
  7. Critical Section class
  8. Author:
  9. Steve Kiraly (SteveKi) 30-Mar-1997
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "dbgcs.hxx"
  15. TDebugCriticalSection::
  16. TDebugCriticalSection(
  17. VOID
  18. ) : m_bValid( FALSE )
  19. {
  20. Initialize();
  21. }
  22. TDebugCriticalSection::
  23. ~TDebugCriticalSection(
  24. VOID
  25. )
  26. {
  27. Release();
  28. }
  29. BOOL
  30. TDebugCriticalSection::
  31. bValid(
  32. VOID
  33. ) const
  34. {
  35. return m_bValid;
  36. }
  37. VOID
  38. TDebugCriticalSection::
  39. Enter(
  40. VOID
  41. )
  42. {
  43. EnterCriticalSection( &m_CriticalSection );
  44. }
  45. VOID
  46. TDebugCriticalSection::
  47. Leave(
  48. VOID
  49. )
  50. {
  51. LeaveCriticalSection( &m_CriticalSection );
  52. }
  53. VOID
  54. TDebugCriticalSection::
  55. Initialize(
  56. VOID
  57. )
  58. {
  59. if (!m_bValid)
  60. {
  61. InitializeCriticalSection( &m_CriticalSection );
  62. m_bValid = TRUE;
  63. }
  64. }
  65. VOID
  66. TDebugCriticalSection::
  67. Release(
  68. VOID
  69. )
  70. {
  71. if (m_bValid)
  72. {
  73. DeleteCriticalSection( &m_CriticalSection );
  74. m_bValid = FALSE;
  75. }
  76. }
  77. TDebugCriticalSection::TLock::
  78. TLock(
  79. TDebugCriticalSection &CriticalSection
  80. ) : m_CriticalSection( CriticalSection )
  81. {
  82. m_CriticalSection.Enter();
  83. }
  84. TDebugCriticalSection::TLock::
  85. ~TLock(
  86. VOID
  87. )
  88. {
  89. m_CriticalSection.Leave();
  90. }
  91. TDebugCriticalSection::TUnLock::
  92. TUnLock(
  93. TDebugCriticalSection &CriticalSection
  94. ) : m_CriticalSection( CriticalSection )
  95. {
  96. m_CriticalSection.Leave();
  97. }
  98. TDebugCriticalSection::TUnLock::
  99. ~TUnLock(
  100. VOID
  101. )
  102. {
  103. m_CriticalSection.Enter();
  104. }