diff --git a/src/libCom/osi/os/RTEMS/osdThread.c b/src/libCom/osi/os/RTEMS/osdThread.c index fb6f0052d..5959709df 100644 --- a/src/libCom/osi/os/RTEMS/osdThread.c +++ b/src/libCom/osi/os/RTEMS/osdThread.c @@ -361,25 +361,11 @@ void threadOnceOsd(threadOnceId *id, void(*func)(void *), void *arg) rtems_task_mode(mode, RTEMS_PREEMPT_MASK, &mode); } semMutexMustTake(onceMutex); - switch (id->state) { - case 0: - id->state = -1; - id->sem = semMutexMustCreate(); - semMutexMustTake(id->sem); - semMutexGive(onceMutex); + if (*id == 0) { func(arg); - id->state = 1; - semBinaryGive(id->sem); - break; - case -1: - semMutexGive(onceMutex); - semBinaryMustTake(id->sem); - semBinaryGive(id->sem); - break; - default: - semMutexGive(onceMutex); - break; + *id = 1; } + semMutexGive(onceMutex); } /* diff --git a/src/libCom/osi/os/posix/osdThread.c b/src/libCom/osi/os/posix/osdThread.c index 1d0e3baab..0231881bf 100644 --- a/src/libCom/osi/os/posix/osdThread.c +++ b/src/libCom/osi/os/posix/osdThread.c @@ -183,25 +183,11 @@ void threadOnceOsd(threadOnceId *id, void (*func)(void *), void *arg) checkStatusQuit(status,"pthread_once","threadOnce"); semMutexMustTake(onceMutex); - switch (id->state) { - case 0: - id->state = -1; - id->mutex = semMutexMustCreate(); - semMutexMustTake(id->mutex); - semMutexGive(onceMutex); - func(arg); - id->state = 1; - semMutexGive(id->mutex); - break; - case -1: - semMutexGive(onceMutex); - semMutexMustTake(id->mutex); - semMutexGive(id->mutex); - break; - default: - semMutexGive(onceMutex); - break; + if (*id == 0) { + func(arg); + *id = 1; } + semMutexGive(onceMutex); } static void * start_routine(void *arg) diff --git a/src/libCom/osi/os/vxWorks/osdThread.c b/src/libCom/osi/os/vxWorks/osdThread.c index e35fc7846..fb489de54 100644 --- a/src/libCom/osi/os/vxWorks/osdThread.c +++ b/src/libCom/osi/os/vxWorks/osdThread.c @@ -77,7 +77,7 @@ void threadOnceOsd(threadOnceId *id, void (*func)(void *), void *arg) { /* not a good implementation (no guarantee that func() has finished before the next task calls this routine); see the Posix implementation */ - if(vxTas(&id->state)) + if(vxTas(*id)) func(arg); } diff --git a/src/libCom/osi/osiThread.h b/src/libCom/osi/osiThread.h index 11875e121..200870c32 100644 --- a/src/libCom/osi/osiThread.h +++ b/src/libCom/osi/osiThread.h @@ -34,11 +34,9 @@ typedef enum { epicsShareFunc unsigned int epicsShareAPI threadGetStackSize(threadStackSizeClass size); /* threadOnce is a macro for efficiency (calls threadOnceOsd) */ -typedef struct { - int state; semMutexId mutex; -} threadOnceId; +typedef int threadOnceId; -#define OSITHREAD_ONCE_INIT {0,0} +#define OSITHREAD_ONCE_INIT 0 epicsShareFunc void epicsShareAPI threadOnceOsd( threadOnceId *id, void (*func)(void *), void *arg); @@ -46,7 +44,7 @@ epicsShareFunc void epicsShareAPI threadOnceOsd( #define threadOnce(id,func,arg) \ do { \ threadOnceId *idCopy =(id); \ - if((idCopy->state) <= 0) \ + if(*idCopy == 0) \ threadOnceOsd(idCopy,func,arg); \ } while(0)