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.

81 lines
1.4 KiB

  1. /*****************************************************************************\
  2. * Class CriticalSection - Implementation
  3. *
  4. * Copyright (C) 1998 Microsoft Corporation
  5. *
  6. * History:
  7. * Jun 10, 1998, Weihai Chen (weihaic)
  8. *
  9. \*****************************************************************************/
  10. #include "spllibp.hxx"
  11. CCriticalSection::CCriticalSection (void):
  12. m_bValid (TRUE)
  13. {
  14. m_bValid = InitializeCriticalSectionAndSpinCount (&m_csec,0x80000000);
  15. }
  16. CCriticalSection::~CCriticalSection (void)
  17. {
  18. if (m_bValid) {
  19. DeleteCriticalSection (&m_csec);
  20. }
  21. }
  22. BOOL
  23. CCriticalSection::Lock (void)
  24. const
  25. {
  26. BOOL bRet;
  27. if (m_bValid) {
  28. EnterCriticalSection ((PCRITICAL_SECTION) &m_csec);
  29. bRet = TRUE;
  30. }
  31. else {
  32. bRet = FALSE;
  33. }
  34. return bRet;
  35. }
  36. BOOL
  37. CCriticalSection::Unlock (void)
  38. const
  39. {
  40. BOOL bRet;
  41. if (m_bValid) {
  42. LeaveCriticalSection ((PCRITICAL_SECTION) &m_csec);
  43. bRet = TRUE;
  44. }
  45. else {
  46. bRet = FALSE;
  47. }
  48. return TRUE;
  49. }
  50. TAutoCriticalSection::TAutoCriticalSection (
  51. CONST TCriticalSection & refCrit):
  52. m_pCritSec (refCrit)
  53. {
  54. m_bValid = m_pCritSec.Lock ();
  55. }
  56. TAutoCriticalSection::~TAutoCriticalSection ()
  57. {
  58. if (m_bValid)
  59. m_pCritSec.Unlock ();
  60. }
  61. BOOL
  62. TAutoCriticalSection::bValid (VOID)
  63. {
  64. return m_bValid;
  65. };