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.

93 lines
2.0 KiB

  1. /*****************************************************************************
  2. * Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  3. *
  4. * All Rights Reserved
  5. *
  6. * This software is furnished under a license and may be used and copied
  7. * only in accordance with the terms of such license and with the inclusion
  8. * of the above copyright notice. This software or any other copies thereof
  9. * may not be provided or otherwise made available to any other person. No
  10. * title to and ownership of the software is hereby transferred.
  11. *****************************************************************************/
  12. //============================================================================
  13. //
  14. // CCriticalSec.cpp -- Critical Section Wrapper
  15. //
  16. // Copyright (c) 1998-2002 Microsoft Corporation, All Rights Reserved
  17. //
  18. // Revisions: 6/26/98 a-kevhu Created
  19. //
  20. //============================================================================
  21. #include "precomp.h"
  22. #include "CCriticalSec.h"
  23. DWORD BreakOnDbgAndRenterLoop(void)
  24. {
  25. __try
  26. {
  27. DebugBreak();
  28. }
  29. _except (EXCEPTION_EXECUTE_HANDLER) {};
  30. return EXCEPTION_CONTINUE_EXECUTION;
  31. };
  32. BOOL CStaticCritSec::anyFailed_ = FALSE;
  33. CStaticCritSec::CStaticCritSec(): initialized_(false)
  34. {
  35. InitializeCriticalSectionAndSpinCount(this,0)?(initialized_ = true) :(anyFailed_ = TRUE);
  36. }
  37. CStaticCritSec::~CStaticCritSec()
  38. {
  39. if(initialized_)
  40. DeleteCriticalSection(this);
  41. }
  42. void CStaticCritSec::Enter()
  43. {
  44. __try {
  45. EnterCriticalSection(this);
  46. } __except((STATUS_POSSIBLE_DEADLOCK == GetExceptionCode())? BreakOnDbgAndRenterLoop():EXCEPTION_CONTINUE_SEARCH) {
  47. }
  48. }
  49. void CStaticCritSec::Leave()
  50. {
  51. LeaveCriticalSection(this);
  52. }
  53. BOOL CStaticCritSec::anyFailure()
  54. {
  55. return anyFailed_;
  56. };
  57. void CStaticCritSec::SetFailure()
  58. {
  59. anyFailed_ = TRUE;
  60. };