Browse Source

Implement TryWait for hsSemaphore

Adam Johnson 12 years ago
parent
commit
43b9535e96
  1. 1
      Sources/Plasma/CoreLib/hsThread.h
  2. 12
      Sources/Plasma/CoreLib/hsThread_Unix.cpp
  3. 7
      Sources/Plasma/CoreLib/hsThread_Win.cpp

1
Sources/Plasma/CoreLib/hsThread.h

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

12
Sources/Plasma/CoreLib/hsThread_Unix.cpp

@ -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

7
Sources/Plasma/CoreLib/hsThread_Win.cpp

@ -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)

Loading…
Cancel
Save