From a99697e2c829d4979a79c7aab086184389b591a6 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 15 Apr 2024 14:42:15 -0700 Subject: [PATCH] asTrapWriteRegisterListener() safe lazy init --- modules/libcom/src/as/asTrapWrite.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/libcom/src/as/asTrapWrite.c b/modules/libcom/src/as/asTrapWrite.c index ec5f0d1478..1bb3134127 100644 --- a/modules/libcom/src/as/asTrapWrite.c +++ b/modules/libcom/src/as/asTrapWrite.c @@ -22,6 +22,7 @@ #include "ellLib.h" #include "freeList.h" +#include "epicsThread.h" #include "cantProceed.h" #include "epicsMutex.h" #include "ellLib.h" @@ -57,9 +58,10 @@ typedef struct asTrapWritePvt epicsMutexId lock; }asTrapWritePvt; +static epicsThreadOnceId asTrapWriteOnce = EPICS_THREAD_ONCE_INIT; static asTrapWritePvt *pasTrapWritePvt = 0; -static void asTrapWriteInit(void) +static void asTrapWriteInit(void *unused) { pasTrapWritePvt = callocMustSucceed(1,sizeof(asTrapWritePvt),"asTrapWriteInit"); ellInit(&pasTrapWritePvt->listenerList); @@ -75,7 +77,7 @@ asTrapWriteId epicsStdCall asTrapWriteRegisterListener( asTrapWriteListener func) { listener *plistener; - if(pasTrapWritePvt==0) asTrapWriteInit(); + epicsThreadOnce(&asTrapWriteOnce, &asTrapWriteInit, NULL); plistener = callocMustSucceed(1,sizeof(listener),"asTrapWriteRegisterListener"); plistener->func = func; epicsMutexMustLock(pasTrapWritePvt->lock);