diff --git a/src/libCom/osi/os/posix/osdSem.c b/src/libCom/osi/os/posix/osdSem.c index 0873cf112..83e786557 100644 --- a/src/libCom/osi/os/posix/osdSem.c +++ b/src/libCom/osi/os/posix/osdSem.c @@ -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)) diff --git a/src/libCom/osi/os/posix/osdThread.c b/src/libCom/osi/os/posix/osdThread.c index 698469436..519a69583 100644 --- a/src/libCom/osi/os/posix/osdThread.c +++ b/src/libCom/osi/os/posix/osdThread.c @@ -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);