mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Fixes for semaphores on *nix.
This commit is contained in:
@ -284,6 +284,7 @@ hsSemaphore::hsSemaphore(int initialValue, const char* name)
|
|||||||
} else {
|
} else {
|
||||||
/* Anonymous semaphore shared between threads */
|
/* Anonymous semaphore shared between threads */
|
||||||
int shared = 0; // 1 if sharing between processes
|
int shared = 0; // 1 if sharing between processes
|
||||||
|
fPSema = new sem_t;
|
||||||
int status = sem_init(fPSema, shared, initialValue);
|
int status = sem_init(fPSema, shared, initialValue);
|
||||||
hsThrowIfOSErr(status);
|
hsThrowIfOSErr(status);
|
||||||
}
|
}
|
||||||
@ -307,6 +308,7 @@ hsSemaphore::~hsSemaphore()
|
|||||||
} else {
|
} else {
|
||||||
status = sem_destroy(fPSema);
|
status = sem_destroy(fPSema);
|
||||||
}
|
}
|
||||||
|
delete fPSema;
|
||||||
hsThrowIfOSErr(status);
|
hsThrowIfOSErr(status);
|
||||||
#else
|
#else
|
||||||
int status = ::pthread_cond_destroy(&fPCond);
|
int status = ::pthread_cond_destroy(&fPCond);
|
||||||
@ -321,7 +323,10 @@ bool hsSemaphore::TryWait()
|
|||||||
{
|
{
|
||||||
#ifdef USE_SEMA
|
#ifdef USE_SEMA
|
||||||
int status = ::sem_trywait(fPSema);
|
int status = ::sem_trywait(fPSema);
|
||||||
return status != EAGAIN;
|
if (status != 0) {
|
||||||
|
return errno != EAGAIN;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
#else
|
#else
|
||||||
int status = ::pthread_mutex_trylock(&fPMutex);
|
int status = ::pthread_mutex_trylock(&fPMutex);
|
||||||
hsThrowIfOSErr(status);
|
hsThrowIfOSErr(status);
|
||||||
|
Reference in New Issue
Block a user