prevent problems when threadInit not called
This commit is contained in:
@@ -121,6 +121,7 @@ semTakeStatus semBinaryTake(semBinaryId id)
|
||||
binary *pbinary = (binary *)id;
|
||||
int status;
|
||||
|
||||
if(!pbinary) return(semTakeError);
|
||||
status = pthread_mutex_lock(&pbinary->mutex);
|
||||
checkStatusQuit(status,"pthread_mutex_lock","semBinaryTake");
|
||||
if(!pbinary->isFull) {
|
||||
@@ -234,6 +235,7 @@ semTakeStatus semMutexTake(semMutexId id)
|
||||
pthread_t tid = pthread_self();
|
||||
int status;
|
||||
|
||||
if(!pmutex || !tid) return(semTakeError);
|
||||
status = pthread_mutex_lock(&pmutex->lock);
|
||||
checkStatusQuit(status,"pthread_mutex_lock","semMutexTake");
|
||||
while(pmutex->owned && !pthread_equal(pmutex->ownerTid,tid))
|
||||
|
||||
@@ -253,7 +253,12 @@ void threadInit(void)
|
||||
/* threadOnce is a macro that calls threadOnceOsd */
|
||||
void threadOnceOsd(threadOnceId *id, void (*func)(void *), void *arg)
|
||||
{
|
||||
semMutexMustTake(onceMutex);
|
||||
|
||||
if(semMutexTake(onceMutex) != semTakeOK) {
|
||||
fprintf(stderr,"threadOnceOsd semMutexTake failed.\n");
|
||||
fprintf(stderr,"Did you call threadInit? Program exiting\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (*id == 0) { /* 0 => first call */
|
||||
*id = -1; /* -1 => func() active */
|
||||
func(arg);
|
||||
|
||||
Reference in New Issue
Block a user