Listing 4: The monitor class implementation

#include "CMonMutex.h"

CMonMutex::CMonMutex()
{
   m_hMutex = CreateMutex( NULL, FALSE, NULL );
}

CMonMutex::~CMonMutex()
{
   CloseHandle( m_hMutex );
}

void
CMonMutex::wait(unsigned short usTimeOut )
   throw (MutexException)
{
   DWORD    dwResult;

   dwResult =
      WaitForSingleObject(m_hMutex, usTimeOut);

   if( dwResult == WAIT_OBJECT_0 )
      return;

   if( dwResult == WAIT_ABANDONED )
      throw(ABANDONED);

   if( dwResult == WAIT_TIMEOUT )
      throw(TIMEOUT);
}

void CMonMutex::release()
{
   ReleaseMutex( m_hMutex );
}
//End of File