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.

66 lines
1.3 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File : Lock.h
  4. Content: Implementation of CLock class.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __LOCK_H_
  8. #define __LOCK_H_
  9. class CLock
  10. {
  11. public:
  12. CLock()
  13. {
  14. __try
  15. {
  16. ::InitializeCriticalSection(&m_CriticalSection);
  17. m_Initialized = S_OK;
  18. }
  19. __except(EXCEPTION_EXECUTE_HANDLER)
  20. {
  21. m_Initialized = HRESULT_FROM_WIN32(::GetExceptionCode());
  22. }
  23. }
  24. ~CLock()
  25. {
  26. if (SUCCEEDED(m_Initialized))
  27. {
  28. ::DeleteCriticalSection(&m_CriticalSection);
  29. }
  30. }
  31. HRESULT Initialized()
  32. {
  33. return m_Initialized;
  34. }
  35. void Lock()
  36. {
  37. if (SUCCEEDED(m_Initialized))
  38. {
  39. ::EnterCriticalSection(&m_CriticalSection);
  40. }
  41. }
  42. void Unlock()
  43. {
  44. if (SUCCEEDED(m_Initialized))
  45. {
  46. ::LeaveCriticalSection(&m_CriticalSection);
  47. }
  48. }
  49. private:
  50. HRESULT m_Initialized;
  51. CRITICAL_SECTION m_CriticalSection;
  52. };
  53. #endif //__LOCK_H_