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.

98 lines
2.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CriticalSection.cpp
  7. //
  8. // Description:
  9. // This file contains the implementation of the CCriticalSection
  10. // class.
  11. //
  12. // The class CCriticalSection is a simple wrapper around Platform SDK
  13. // spinlock objects.
  14. //
  15. // Documentation:
  16. //
  17. // Header Files:
  18. // CriticalSection.h
  19. //
  20. // Maintained By:
  21. // John Franco (jfranco) 03-Oct-2001
  22. //
  23. //////////////////////////////////////////////////////////////////////////////
  24. //////////////////////////////////////////////////////////////////////////////
  25. // Include Files
  26. //////////////////////////////////////////////////////////////////////////////
  27. #include "pch.h"
  28. #include "CriticalSection.h"
  29. //////////////////////////////////////////////////////////////////////////////
  30. // Constant Definitions
  31. //////////////////////////////////////////////////////////////////////////////
  32. DEFINE_THISCLASS( "CCriticalSection" );
  33. //*************************************************************************//
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CCriticalSection class
  36. /////////////////////////////////////////////////////////////////////////////
  37. //////////////////////////////////////////////////////////////////////////////
  38. //++
  39. //
  40. // CCriticalSection::CCriticalSection
  41. //
  42. // Description:
  43. // Initialize this object's spin lock.
  44. //
  45. // Arguments:
  46. // cSpinsIn
  47. // The number of times the lock should retry entry before calling
  48. // a wait function.
  49. //
  50. // Return Value:
  51. // None.
  52. //
  53. //--
  54. //////////////////////////////////////////////////////////////////////////////
  55. CCriticalSection::CCriticalSection( DWORD cSpinsIn )
  56. : m_hrInitialization( S_OK )
  57. {
  58. if ( InitializeCriticalSectionAndSpinCount( &m_csSpinlock, cSpinsIn ) == 0 )
  59. {
  60. DWORD scLastError = TW32( GetLastError() );
  61. m_hrInitialization = HRESULT_FROM_WIN32( scLastError );
  62. }
  63. } //*** CCriticalSection::CCriticalSection
  64. //////////////////////////////////////////////////////////////////////////////
  65. //++
  66. //
  67. // CCriticalSection::~CCriticalSection
  68. //
  69. // Description:
  70. // Destructor.
  71. //
  72. // Arguments:
  73. // None.
  74. //
  75. // Return Value:
  76. // None.
  77. //
  78. //--
  79. //////////////////////////////////////////////////////////////////////////////
  80. CCriticalSection::~CCriticalSection( void )
  81. {
  82. if ( SUCCEEDED( m_hrInitialization ) )
  83. {
  84. DeleteCriticalSection( &m_csSpinlock );
  85. }
  86. } //*** CCriticalSection::~CCriticalSection