prevent problems when threadInit not called

This commit is contained in:
Marty Kraimer
2000-03-08 18:50:58 +00:00
parent a13bf6cc0e
commit bc42a7d000
2 changed files with 8 additions and 1 deletions
+2
View File
@@ -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))
+6 -1
View File
@@ -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);