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.

112 lines
2.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: critsect.cpp
  7. //
  8. // Contents: critical section helper class
  9. //
  10. // Classes: CCriticalSection
  11. // CLockHandler
  12. // CLock
  13. //
  14. //
  15. // Notes:
  16. //
  17. // History: 13-Nov-97 rogerg Created.
  18. //
  19. //--------------------------------------------------------------------------
  20. #include "lib.h"
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Member: CLockHandler::CLockHandler, public
  24. //
  25. // Synopsis: Constructor
  26. //
  27. // Arguments:
  28. //
  29. // Returns:
  30. //
  31. // Modifies:
  32. //
  33. // History: 05-Nov-97 rogerg Created.
  34. //
  35. //----------------------------------------------------------------------------
  36. CLockHandler::CLockHandler()
  37. {
  38. m_dwLockThreadId = 0;
  39. InitializeCriticalSection(&m_CriticalSection);
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Member: CLockHandler::~CLockHandler, public
  44. //
  45. // Synopsis: Destructor
  46. //
  47. // Arguments:
  48. //
  49. // Returns:
  50. //
  51. // Modifies:
  52. //
  53. // History: 05-Nov-97 rogerg Created.
  54. //
  55. //----------------------------------------------------------------------------
  56. CLockHandler::~CLockHandler()
  57. {
  58. Assert (0 == m_dwLockThreadId);
  59. DeleteCriticalSection(&m_CriticalSection);
  60. }
  61. //+---------------------------------------------------------------------------
  62. //
  63. // Member: CLockHandler::Lock, public
  64. //
  65. // Synopsis: Adds a lock to the specified class
  66. //
  67. // Arguments:
  68. //
  69. // Returns:
  70. //
  71. // Modifies:
  72. //
  73. // History: 05-Nov-97 rogerg Created.
  74. //
  75. //----------------------------------------------------------------------------
  76. void CLockHandler::Lock(DWORD dwThreadId)
  77. {
  78. EnterCriticalSection(&m_CriticalSection);
  79. m_dwLockThreadId = dwThreadId;
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Member: CLockHandler::UnLock, public
  84. //
  85. // Synopsis: Removes a lock to the specified class
  86. //
  87. // Arguments:
  88. //
  89. // Returns:
  90. //
  91. // Modifies:
  92. //
  93. // History: 05-Nov-97 rogerg Created.
  94. //
  95. //----------------------------------------------------------------------------
  96. void CLockHandler::UnLock()
  97. {
  98. m_dwLockThreadId = 0;
  99. LeaveCriticalSection(&m_CriticalSection);
  100. }