diff --git a/src/as/asDbLib.c b/src/as/asDbLib.c index b6561e11e..7090c8ddf 100644 --- a/src/as/asDbLib.c +++ b/src/as/asDbLib.c @@ -111,26 +111,35 @@ static void asSpcAsCallback(struct dbCommon *precord) { asChangeGroup((ASMEMBERPVT *)&precord->asp,precord->asg); } + +static void asInitCommonOnce(void *arg) +{ + int *firstTime = (int *)arg; + *firstTime = FALSE; +} static long asInitCommon(void) { long status; int asWasActive = asActive; + int wasFirstTime = firstTime; + static threadOnceId asInitCommonOnceFlag = OSITHREAD_ONCE_INIT; - if(firstTime) { - firstTime = FALSE; - if(!pacf) return(0); /*access security will NEVER be turned on*/ + + threadOnce(&asInitCommonOnceFlag,asInitCommonOnce,(void *)&firstTime); + if(wasFirstTime) { + if(!pacf) return(0); /*access security will NEVER be turned on*/ } else { - if(!asActive) { + if(!asActive) { printf("Access security is NOT enabled." " Was asSetFilename specified before iocInit?\n"); return(S_asLib_asNotActive); } - if(pacf) { - asCaStop(); - } else { /*Just leave everything as is */ - return(S_asLib_badConfig); - } + if(pacf) { + asCaStop(); + } else { /*Just leave everything as is */ + return(S_asLib_badConfig); + } } status = asInitFile(pacf,psubstitutions); if(asActive) { diff --git a/src/as/asLibRoutines.c b/src/as/asLibRoutines.c index c8c6aff08..cd4c0e6f7 100644 --- a/src/as/asLibRoutines.c +++ b/src/as/asLibRoutines.c @@ -25,6 +25,7 @@ of this distribution. #include #include "dbDefs.h" +#include "osiThread.h" #include "ellLib.h" #include "cantProceed.h" #include "osiSem.h" @@ -48,7 +49,6 @@ epicsShareDef ASBASE volatile *pasbase=NULL; static ASBASE *pasbasenew=NULL; epicsShareDef int asActive = FALSE; -static int asLockInit=TRUE; static void *freeListPvt = NULL; @@ -85,6 +85,10 @@ static long asAsgRuleCalc(ASGRULE *pasgrule,char *calc); the old memberList is moved from old to new. the old structures are freed. */ +static void asInitializeOnce(void *arg) +{ + asLock = semMutexMustCreate(); +} long epicsShareAPI asInitialize(ASINPUTFUNCPTR inputfunction) { ASG *pasg; @@ -95,11 +99,9 @@ long epicsShareAPI asInitialize(ASINPUTFUNCPTR inputfunction) UAGNAME *puagname; HAG *phag; HAGNAME *phagname; + static threadOnceId asInitializeOnceFlag = OSITHREAD_ONCE_INIT; - if(asLockInit) { - asLock = semMutexMustCreate(); - asLockInit = FALSE; - } + threadOnce(&asInitializeOnceFlag,asInitializeOnce,(void *)0); LOCK; pasbasenew = asCalloc(1,sizeof(ASBASE)); if(!freeListPvt) freeListInitPvt(&freeListPvt,sizeof(ASGCLIENT),20);