class CComAutoCriticalSection
CComAutoCriticalSection provides methods for obtaining and releasing ownership of a critical section object. CComAutoCriticalSection is similar to class CComCriticalSection, except CComAutoCriticalSection automatically initializes critical section objects in the constructor.
Typically, you use CComAutoCriticalSection through the typedef name, AutoCriticalSection. This name references CComAutoCriticalSection when CComMultiThreadModel is being used.
You should not use CComAutoCriticalSection in global objects or static class members if you want to eliminate the CRT startup code. In this case, use CComCriticalSection.
#include <atlbase.h>
See Also CComFakeCriticalSection
Methods | |
CComAutoCriticalSection | Constructor. |
Lock | Obtains ownership of a critical section object. |
Unlock | Releases ownership of a critical section object. |
Data Members | |
m_sec | A CRITICAL_SECTION object. |
CComAutoCriticalSection Overview
void CComAutoCriticalSection( );
Remarks
The constructor. Calls the Win32 function InitializeCriticalSection, which initializes the critical section object contained in the m_sec data member.
The destructor calls DeleteCriticalSection, which releases all system resources used by the critical section object.
CComAutoCriticalSection Overview | Class Members
See Also InitializeCriticalSection and DeleteCriticalSection in the Win32 SDK
void Lock( );
Remarks
Calls the Win32 function EnterCriticalSection, which waits until the thread can take ownership of the critical section object contained in the m_sec data member. When the protected code has finished executing, the thread must call Unlock to release ownership of the critical section.
CComAutoCriticalSection Overview | Class Members
See Also EnterCriticalSection in the Win32 SDK
void Unlock( );
Remarks
Calls the Win32 function LeaveCriticalSection, which releases ownership of the critical section object contained in the m_sec data member. To first obtain ownership, the thread must call the Lock method. Each call to Lock then requires a corresponding call to Unlock to release ownership of the critical section.
CComAutoCriticalSection Overview | Class Members
See Also LeaveCriticalSection in the Win32 SDK
CRITICAL_SECTION m_sec;
Remarks
Contains a critical section object that is used by all CComAutoCriticalSection methods.
CComAutoCriticalSection Overview | Class Members
See Also CComAutoCriticalSection::CComAutoCriticalSection, CComAutoCriticalSection::Lock, CComAutoCriticalSection::Unlock