4
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

48 lines
741 B

#include "IEvent.h"
IEvent::IEvent()
{
theEvent = CreateEvent(NULL, true, true, NULL);
ASSERT(theEvent);
blockCount.Set(0);
}
IEvent::~IEvent()
{
CloseHandle(theEvent);
}
bool IEvent::Block(void)
{
if(blockCount.Increment() == 1)
return (ResetEvent(theEvent) != 0);
else
return true;
}
bool IEvent::UnBlock(void)
{
if(blockCount.Decrement() == 0)
return (SetEvent(theEvent) != 0);
else
return true;
}
bool IEvent::Wait(UInt32 timeout)
{
switch(WaitForSingleObject(theEvent, timeout))
{
case WAIT_ABANDONED:
HALT("IEvent::Wait: got abandoned event");
return false;
case WAIT_OBJECT_0:
return true;
default:
case WAIT_TIMEOUT:
gLog.FormattedMessage("IEvent::Wait: timeout");
return false;
}
}