Back to the WFC main pageCCriticalSectionGuard
$Revision: 7 $
Description
This class makes it easy to use a
CCriticalSection (an MFC class).
The critical section is entered in the contructor and left in the
destructor. This reduces coding mistakes when you have functions with
multiple returns. When the
CCriticalSectionGuard class falls
out of scope, the critical section is unlocked. It makes cleanup easy.
This ensures that the critical section will be exitted no matter where
you choose to exit the function.
Constructors
CCriticalSectionGuard( CCriticalSection * section )
CCriticalSectionGuard( CCriticalSection& section )
-
Constructs the object. It calls the Lock() method of the
CCriticalSection. The destructor calls Unlock().
Example
void CMyClass::Method( void )
{
CCriticalSectionGuard guard( m_MyCriticialSection );
if ( ::GetTickCount() % 2 ) == 1 )
{
return;
}
if ( ::GetTickCount() % 5 ) == 0 )
{
return;
}
::KillTimer( m_WindowHandle, 1 );
}
Copyright, 2000, Samuel R. Blackburn
$Workfile: CCriticalSectionGuard.cpp $
$Modtime: 1/04/00 5:09a $