Source code of Windows XP (NT5)
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.

37 lines
684 B

  1. #pragma once
  2. class CCriticalSection
  3. {
  4. public:
  5. CCriticalSection(CRITICAL_SECTION *pcs)
  6. : _pcs(pcs)
  7. {
  8. // ASSERT(pcs);
  9. }
  10. HRESULT Lock()
  11. {
  12. HRESULT hr = S_OK;
  13. __try {
  14. ::EnterCriticalSection(_pcs);
  15. }
  16. __except (EXCEPTION_EXECUTE_HANDLER) {
  17. hr = E_OUTOFMEMORY;
  18. }
  19. return hr;
  20. }
  21. HRESULT Unlock()
  22. {
  23. ::LeaveCriticalSection(_pcs);
  24. return S_OK;
  25. }
  26. private:
  27. CRITICAL_SECTION *_pcs;
  28. };