#include "StdAfx.h"
#include "SysSemaphore.h"

SysSemaphore::SysSemaphore(void) :
	m_id(0)
{
   //m_id = ::CreateMutex(NULL, FALSE, NULL);
	m_id = ::CreateSemaphore( NULL, 1, 1, NULL );
}


SysSemaphore::~SysSemaphore(void)
{
   ::CloseHandle(m_id);
}

bool SysSemaphore::Lock(INT32 timeout_milliseconds)
{
   return (::WaitForSingleObject(m_id, timeout_milliseconds) == WAIT_OBJECT_0);
}

bool SysSemaphore::Unlock(void)
{
//	return ::ReleaseMutex(m_id) == TRUE;
	return ::ReleaseSemaphore(m_id,1,NULL) == TRUE;
}
