2 #include <msp/core/systemerror.h>
3 #include <msp/time/units.h>
8 struct Semaphore::Private
14 Semaphore::Semaphore(unsigned limit):
17 priv->handle = CreateSemaphore(0, 0, limit, 0);
20 Semaphore::~Semaphore()
22 CloseHandle(priv->handle);
26 void Semaphore::signal()
28 if(!ReleaseSemaphore(priv->handle, 1, 0))
29 throw system_error("ReleaseSemaphore");
32 void Semaphore::wait()
34 DWORD ret = WaitForSingleObject(priv->handle, INFINITE);
36 throw system_error("WaitForSingleObject");
39 bool Semaphore::wait(const Time::TimeDelta &d)
41 DWORD ret = WaitForSingleObject(priv->handle, (DWORD)(d/Time::usec));
43 throw system_error("WaitForSingleObject");
44 return ret==WAIT_OBJECT_0;