epicsThreadOnceOsd() must unlock mutex before calling func().

Required so callbackInit() can wait for its threads to start.
This commit is contained in:
Andrew Johnson
2008-06-24 20:59:55 +00:00
parent 13922ddd8d
commit df39142335
3 changed files with 9 additions and 3 deletions
+5 -3
View File
@@ -478,9 +478,11 @@ void epicsThreadOnceOsd(epicsThreadOnceId *id, void(*func)(void *), void *arg)
if (!initialized) epicsThreadInit();
epicsMutexMustLock(onceMutex);
if (*id == 0) {
*id = -1;
func(arg);
*id = 1;
*id = -1;
epicsMutexUnlock(onceMutex);
func(arg);
epicsMutexMustLock(onceMutex);
*id = 1;
} else
assert(*id > 0 /* func() called epicsThreadOnce() with same id */);
epicsMutexUnlock(onceMutex);
+2
View File
@@ -1004,7 +1004,9 @@ epicsShareFunc void epicsShareAPI epicsThreadOnceOsd (
if ( *id == 0 ) {
*id = -1;
LeaveCriticalSection ( & pGbl->mutex );
( *func ) ( arg );
EnterCriticalSection ( & pGbl->mutex );
*id = 1;
} else
assert(*id > 0 /* func() called epicsThreadOnce() with same id */);
+2
View File
@@ -116,7 +116,9 @@ void epicsThreadOnceOsd(epicsThreadOnceId *id, void (*func)(void *), void *arg)
assert(semTake(epicsThreadOnceMutex,WAIT_FOREVER)==OK);
if (*id == 0) { /* 0 => first call */
*id = -1; /* -1 => func() active */
semGive(epicsThreadOnceMutex);
func(arg);
assert(semTake(epicsThreadOnceMutex,WAIT_FOREVER)==OK);
*id = +1; /* +1 => func() done */
} else
assert(*id > 0 /* func() called epicsThreadOnce() with same id */);