Skip to content

Commit

Permalink
asTrapWriteRegisterListener() safe lazy init
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Dec 30, 2024
1 parent 62d8f37 commit a99697e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/libcom/src/as/asTrapWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "ellLib.h"
#include "freeList.h"
#include "epicsThread.h"
#include "cantProceed.h"
#include "epicsMutex.h"
#include "ellLib.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a99697e

Please sign in to comment.