From bc42a7d000a8b285bf71076ba0cdf0728a170828 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Wed, 8 Mar 2000 18:50:58 +0000 Subject: [PATCH] prevent problems when threadInit not called --- src/libCom/osi/os/posix/osdSem.c | 2 ++ src/libCom/osi/os/posix/osdThread.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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);