CComCritSecLock Class

 

The latest version of this topic can be found at CComCritSecLock Class.

This class provides methods for locking and unlocking a critical section object.

Syntax

template<class TLock> class CComCritSecLock

Parameters

TLock
The object to be locked and unlocked.

Members

Public Constructors

Name Description
CComCritSecLock::CComCritSecLock The constructor.
CComCritSecLock::~CComCritSecLock The destructor.

Public Methods

Name Description
CComCritSecLock::Lock Call this method to lock the critical section object.
CComCritSecLock::Unlock Call this method to unlock the critical section object.

Remarks

Use this class to lock and unlock objects in a safer way than with the CComCriticalSection Class or CComAutoCriticalSection Class.

Requirements

Header: atlbase.h

CComCritSecLock::CComCritSecLock

The constructor.

CComCritSecLock(TLock& cs, bool bInitialLock = true);

Parameters

cs
The critical section object.

bInitialLock
The initial lock state: true means locked.

Remarks

Initializes the critical section object.

CComCritSecLock::~CComCritSecLock

The destructor.

~CComCritSecLock() throw();

Remarks

Unlocks the critical section object.

CComCritSecLock::Lock

Call this method to lock the critical section object.

HRESULT Lock() throw();

Return Value

Returns S_OK if the object has successfully been locked, or an error HRESULT on failure.

Remarks

If the object is already locked, an ASSERT error will occur in debug builds.

CComCritSecLock::Unlock

Call this method to unlock the critical section object.

void Unlock() throw();

Remarks

If the object is already unlocked, an ASSERT error will occur in debug builds.

See Also

CComCriticalSection Class
CComAutoCriticalSection Class