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
2.2 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. CritSec.cpp
  5. Abstract:
  6. This file provides implementation of the service
  7. critical section wrapper.
  8. Author:
  9. Oded Sacher (OdedS) Nov, 2000
  10. Revision History:
  11. --*/
  12. #include "CritSec.h"
  13. /***********************************
  14. * *
  15. * CFaxCriticalSection Methodes *
  16. * *
  17. ***********************************/
  18. extern long
  19. StatusNoMemoryExceptionFilter (DWORD dwExceptionCode); // Implemented in mem.c
  20. BOOL
  21. CFaxCriticalSection::Initialize()
  22. /*++
  23. Routine name : CFaxCriticalSection::Initialize
  24. Routine description:
  25. Initialize a critical section object
  26. Author:
  27. Oded Sacher (OdedS), Nov, 2000
  28. Arguments:
  29. Return Value:
  30. BOOL.
  31. --*/
  32. {
  33. Assert (FALSE == m_bInit);
  34. __try
  35. {
  36. InitializeCriticalSection (&m_CritSec);
  37. }
  38. __except (StatusNoMemoryExceptionFilter(GetExceptionCode()))
  39. {
  40. SetLastError(GetExceptionCode());
  41. return FALSE;
  42. }
  43. m_bInit = TRUE;
  44. return TRUE;
  45. } // CFaxCriticalSection::Initialize
  46. #if (_WIN32_WINNT >= 0x0403)
  47. BOOL
  48. CFaxCriticalSection::InitializeAndSpinCount(DWORD dwSpinCount)
  49. /*++
  50. Routine name : CFaxCriticalSection::InitializeAndSpinCount
  51. Routine description:
  52. Initialize a critical section object with spin count
  53. Author:
  54. Oded Sacher (OdedS), Nov, 2000
  55. Arguments:
  56. Return Value:
  57. BOOL
  58. --*/
  59. {
  60. Assert (FALSE == m_bInit);
  61. if (!InitializeCriticalSectionAndSpinCount (&m_CritSec, dwSpinCount))
  62. {
  63. return FALSE;
  64. }
  65. m_bInit = TRUE;
  66. return TRUE;
  67. } // CFaxCriticalSection::InitializeAndSpinCount
  68. #endif
  69. VOID
  70. CFaxCriticalSection::SafeDelete()
  71. /*++
  72. Routine name : CFaxCriticalSection::SafeDelete
  73. Routine description:
  74. Deletes a critical section object if it is initialized
  75. Author:
  76. Oded Sacher (OdedS), Nov, 2000
  77. Arguments:
  78. Return Value:
  79. --*/
  80. {
  81. if (TRUE == m_bInit)
  82. {
  83. DeleteCriticalSection(&m_CritSec);
  84. m_bInit = FALSE;
  85. }
  86. return;
  87. } // CFaxCriticalSection::SafeDelete