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.

49 lines
1023 B

  1. /*==========================================================================
  2. * Copyright (C) 1999, 2000 Microsoft Corporation. All Rights Reserved.
  3. *
  4. * File: dvcslock.h
  5. * Content: Class to handle auto-leave of critical sections
  6. * History:
  7. * Date By Reason
  8. * ==== == ======
  9. * 07/05/00 rodtoll Created It
  10. *
  11. ***************************************************************************/
  12. #ifndef __DVCSLOCK_H
  13. #define __DVCSLOCK_H
  14. // CDVCSLock
  15. //
  16. // A class to provide automatic unlocking of critical sections when the object
  17. // passes out of scope.
  18. //
  19. class CDVCSLock
  20. {
  21. public:
  22. CDVCSLock( DNCRITICAL_SECTION *pcs ): m_pcs( pcs ), m_fLocked( FALSE )
  23. {
  24. };
  25. ~CDVCSLock()
  26. {
  27. if( m_fLocked ) DNLeaveCriticalSection( m_pcs );
  28. }
  29. void Lock()
  30. {
  31. DNEnterCriticalSection( m_pcs );
  32. m_fLocked = TRUE;
  33. }
  34. void Unlock()
  35. {
  36. DNLeaveCriticalSection( m_pcs );
  37. m_fLocked = FALSE;
  38. }
  39. private:
  40. DNCRITICAL_SECTION *m_pcs;
  41. BOOL m_fLocked;
  42. };
  43. #endif