// CritSec.ccp V0.1pre Provides class Crit_Sec member functions
// © 2003 Elliot Nierman

 

//Crit_Sec( )
// Default constructor
Crit_Sec::Crit_Sec()
{

#ifdef WIN
InitializeCriticalSection(&CSec);
#endif

#ifdef POSIX
pthread_mutex_init(&mtx, NULL);
#endif

}

//~Crit_Sec( )
// Default destructor, frees system resources
Crit_Sec::~Crit_Sec()
{

#ifdef WIN
DeleteCriticalSection(&CSec);
#endif

#ifdef POSIX
pthread_mutex_destroy(&mtx);
#endif

}


//Enter( )
// Enter a critical section of code
void Crit_Sec::Enter()
{

#ifdef WIN
EnterCriticalSection(&CSec);
#endif

#ifdef POSIX
pthread_mutex_lock(&mtx);
#endif

}//end Enter


//Leave( )
// Leave a critical section of code
void Crit_Sec::Leave()
{
#ifdef WIN
LeaveCriticalSection(&CSec);
#endif

#ifdef POSIX
pthread_mutex_unlock(&mtx);
#endif
}