Microsoft DirectX 8.0

CCritSec Class

CCritSec class hierarchy

Provides a thread lock.

Declaration: Wxutil.h

This class is a wrapper for a critical section. You can lock and unlock the thread by calling the Lock and Unlock methods. However, it is safer to use this class in conjunction with the CAutoLock class. When the CAutoLock class goes out of scope, it automatically unlocks the CCritSec object. Moreover, it compiles to efficient inline code.

Public Member Variables
m_currentOwnerThread identifier of the owning thread.
m_lockCountNumber of outstanding locks on this object.
m_fTraceBoolean value that specifies whether to trace this lock.
Public Methods
CCritSecConstructor method.
~CCritSecDestructor method.
LockLocks the critical section object.
UnlockUnlocks the critical section object.

CCritSec.m_currentOwner

CCritSec Class

Thread identifier of the owning thread.

Syntax

DWORD m_currentOwner;

Remarks

This member variable is defined only in the debug version of the base class. The CCritSec debug functions use this member.

CCritSec.m_lockCount

CCritSec Class

Number of outstanding locks on this object.

Syntax

DWORD m_lockCount;

Remarks

This member variable is defined only in the debug version of the base class. The CCritSec debug functions use this member.

CCritSec.m_fTrace

CCritSec Class

Boolean value that specifies whether to trace this lock.

Syntax

BOOL m_fTrace;

Remarks

This member variable is defined only in the debug version of the base class. If the value is TRUE, a trace of the lock state is written to the debug log. (Debug logging for critical sections must be active.) For more information, see DbgLockTrace.

CCritSec::CCritSec

CCritSec Class

Constructor method.

Syntax

CCritSec(void);

Remarks

This method calls the Microsoft® Win32® InitializeCriticalSection function to initialize the critical section.

CCritSec::~CCritSec

CCritSec Class

Destructor method.

Syntax

~CCritSec(void);

Remarks

This method calls the Microsoft® Win32® DeleteCriticalSection function to delete the critical section.

CCritSec::Lock

CCritSec Class

Locks the critical section object.

Syntax

void Lock(void);

Return Value

No return value.

Remarks

This method calls the Microsoft® Win32® EnterCriticalSection method.

Call the CCritSec::Unlock member function to unlock the critical section. You can make multiple calls to the Lock method on the same thread; be sure to call Unlock a corresponding number of times.

If the object is already locked by another thread, the CCritSec::Lock method blocks until the object is released, or until a possible-deadlock exception occurs.

CCritSec::Unlock

CCritSec Class

Unlocks the critical section object.

Syntax

void Unlock(void);

Return Value

No return value.

Remarks

This method calls the Microsoft® Win32® LeaveCriticalSection method.

Call this method once for each call to the Lock method.