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.
 
 
 
 
 
 

38 lines
1.3 KiB

#ifndef _CLOCK_HXX_
#define _CLOCK_HXX_
//+--------------------------------------------------------------------------
//
// Class: CLock
//
// Purpose: Auto-unlocking critical-section services
//
// Interface: Lock - locks the critical section
// Unlock - unlocks the critical section
// Constructor - locks the critical section (unless told
// otherwise)
// Detructor - unlocks the critical section if its locked
//
// Notes: This provides a convenient way to ensure that you're
// unlocking a LOCK, which is useful if your routine
// can be left via several returns and/or via exceptions....
//
//---------------------------------------------------------------------------
class CLock {
public:
CLock (LOCK* val) : m_pSem(val), m_locked(TRUE) { m_pSem->Lock(); }
CLock (LOCK& val) : m_pSem(&val), m_locked(TRUE) { m_pSem->Lock(); }
CLock (LOCK* val, BOOL fLockMe) : m_pSem(val), m_locked(fLockMe) { if (fLockMe) m_pSem->Lock(); }
~CLock () { if (m_locked) m_pSem->Unlock(); }
void UnLock () { if (m_locked) { m_pSem->Unlock(); m_locked = FALSE; }}
void Lock () { if (!m_locked) { m_pSem->Lock(); m_locked = TRUE; }}
private:
BOOL m_locked;
LOCK* m_pSem;
};
#endif // !_CLOCK_HXX_