2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-13 18:17:49 -04:00

Implement TryWait for hsSemaphore

This commit is contained in:
2012-03-28 19:24:33 -04:00
parent c70bb776ba
commit 43b9535e96
3 changed files with 20 additions and 0 deletions

View File

@ -157,6 +157,7 @@ public:
hsSemaphore(int initialValue=0, const char* name=nil);
~hsSemaphore();
hsBool TryWait();
hsBool Wait(hsMilliseconds timeToWait = kPosInfinity32);
void Signal();
};

View File

@ -316,6 +316,18 @@ hsSemaphore::~hsSemaphore()
#endif
}
hsBool hsSemaphore::TryWait()
{
#ifdef USE_SEMA
int status = ::sem_trywait(fPSema);
return status != E_AGAIN;
#else
int status = ::pthread_mutex_trylock(&fPMutex);
hsThrowIfOSErr(status);
return status==EBUSY ? false : true;
#endif
}
hsBool hsSemaphore::Wait(hsMilliseconds timeToWait)
{
#ifdef USE_SEMA // SHOULDN'T THIS USE timeToWait??!?!? -rje

View File

@ -170,6 +170,13 @@ hsSemaphore::~hsSemaphore()
::CloseHandle(fSemaH);
}
hsBool hsSemaphore::TryWait()
{
DWORD result = ::WaitForSingleObject(fSemaH, 0);
hsAssert(result != WAIT_ABANDONED, "hsSemaphore -> Abandoned Semaphore");
return result == WAIT_OBJECT_0;
}
hsBool hsSemaphore::Wait(hsMilliseconds timeToWait)
{
if (timeToWait == kPosInfinity32)