mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Implement TryWait for hsSemaphore
This commit is contained in:
@ -157,6 +157,7 @@ public:
|
||||
hsSemaphore(int initialValue=0, const char* name=nil);
|
||||
~hsSemaphore();
|
||||
|
||||
hsBool TryWait();
|
||||
hsBool Wait(hsMilliseconds timeToWait = kPosInfinity32);
|
||||
void Signal();
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user