From f5e99ba9a3ad01d6f3bdfd07b220872bf4411a4d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Thu, 26 Dec 2013 23:49:03 -0800 Subject: [PATCH] Fixes for semaphores on *nix. --- Sources/Plasma/CoreLib/hsThread_Unix.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/Plasma/CoreLib/hsThread_Unix.cpp b/Sources/Plasma/CoreLib/hsThread_Unix.cpp index 7ac17a66..1e298282 100644 --- a/Sources/Plasma/CoreLib/hsThread_Unix.cpp +++ b/Sources/Plasma/CoreLib/hsThread_Unix.cpp @@ -284,6 +284,7 @@ hsSemaphore::hsSemaphore(int initialValue, const char* name) } else { /* Anonymous semaphore shared between threads */ int shared = 0; // 1 if sharing between processes + fPSema = new sem_t; int status = sem_init(fPSema, shared, initialValue); hsThrowIfOSErr(status); } @@ -307,6 +308,7 @@ hsSemaphore::~hsSemaphore() } else { status = sem_destroy(fPSema); } + delete fPSema; hsThrowIfOSErr(status); #else int status = ::pthread_cond_destroy(&fPCond); @@ -321,7 +323,10 @@ bool hsSemaphore::TryWait() { #ifdef USE_SEMA int status = ::sem_trywait(fPSema); - return status != EAGAIN; + if (status != 0) { + return errno != EAGAIN; + } + return true; #else int status = ::pthread_mutex_trylock(&fPMutex); hsThrowIfOSErr(status);