/*! \file guard.h
This is the Guard class definition and implementation inlined.
\author Jon A. Lambert
\date 05/02/2003
\version 0.30
*/
#ifndef GUARD_H
#define GUARD_H
/*!
The Guard class implements a synchronization mechanism based on
the aquistion and release of a CRITICAL_SECTION upon construction
and destruction of a Guard object.
\note
Objects that wish to use this must have a Critical Section, must initialze
it in their constructor (InitializeCriticalSection), and must destroy it
in their destructor (DeleteCriticalSection).
\remarks
BSD and Unix would use mutexes here.
*/
class Guard {
CRITICAL_SECTION &Lock; //!< Reference to Critical Section we are guarding.
public:
/*!
Constructor for Guard class.
\param l A reference to the Object's Critical Section
*/
Guard(CRITICAL_SECTION &l) : Lock(l) {
EnterCriticalSection(&Lock);
}
/*!
Destructor for Guard class.
*/
~Guard() {
LeaveCriticalSection(&Lock);
}
};
#endif // GUARD_H