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.

84 lines
1.5 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. SYNC.CPP
  5. Abstract:
  6. Synchronization
  7. History:
  8. --*/
  9. #include "precomp.h"
  10. #include "statsync.h"
  11. #include <cominit.h>
  12. #include <wbemutil.h>
  13. #include <corex.h>
  14. //
  15. //
  16. // Critical Section to be used when it's a Global or class static
  17. //
  18. ///////////////////////////////////////////////////
  19. #ifndef STATUS_POSSIBLE_DEADLOCK
  20. #define STATUS_POSSIBLE_DEADLOCK (0xC0000194L)
  21. #endif /*STATUS_POSSIBLE_DEADLOCK */
  22. DWORD POLARITY BreakOnDbgAndRenterLoop(void);
  23. BOOL CStaticCritSec::anyFailed_ = FALSE;
  24. // This code is shared at binary level with Win9x.
  25. // InitializeCriticalSectionAndSpinCount is not working in Win9x
  26. CStaticCritSec::CStaticCritSec(): initialized_(false)
  27. {
  28. __try
  29. {
  30. InitializeCriticalSection(this);
  31. initialized_ = true;
  32. }
  33. __except( GetExceptionCode() == STATUS_NO_MEMORY )
  34. {
  35. anyFailed_ = TRUE;
  36. }
  37. }
  38. CStaticCritSec::~CStaticCritSec()
  39. {
  40. if(initialized_)
  41. DeleteCriticalSection(this);
  42. }
  43. void CStaticCritSec::Enter()
  44. {
  45. __try {
  46. EnterCriticalSection(this);
  47. } __except((STATUS_POSSIBLE_DEADLOCK == GetExceptionCode())? BreakOnDbgAndRenterLoop():EXCEPTION_CONTINUE_SEARCH) {
  48. }
  49. }
  50. void CStaticCritSec::Leave()
  51. {
  52. LeaveCriticalSection(this);
  53. }
  54. BOOL CStaticCritSec::anyFailure()
  55. {
  56. return anyFailed_;
  57. };
  58. void CStaticCritSec::SetFailure()
  59. {
  60. anyFailed_ = TRUE;
  61. };