Skip to content
Snippets Groups Projects
Commit a4a18b2b authored by benjamin.franksen's avatar benjamin.franksen
Browse files

seq: add pvSys to globals, add createOrAttachPvSystem, remove pvSys code from addProg

parent b06bfcb7
No related branches found
No related tags found
No related merge requests found
...@@ -247,6 +247,7 @@ void seqAddProg(SPROG *sp); ...@@ -247,6 +247,7 @@ void seqAddProg(SPROG *sp);
/* seqCommands.c */ /* seqCommands.c */
typedef int sequencerProgramTraversee(SPROG **sprog, seqProgram *pseq, void *param); typedef int sequencerProgramTraversee(SPROG **sprog, seqProgram *pseq, void *param);
int traverseSequencerPrograms(sequencerProgramTraversee *traversee, void *param); int traverseSequencerPrograms(sequencerProgramTraversee *traversee, void *param);
void createOrAttachPvSystem(SPROG *sp);
/* seq_main.c */ /* seq_main.c */
void seq_free(SPROG *sp); void seq_free(SPROG *sp);
......
...@@ -30,6 +30,7 @@ static struct ...@@ -30,6 +30,7 @@ static struct
{ {
epicsMutexId lock; epicsMutexId lock;
struct sequencerProgram *programs; struct sequencerProgram *programs;
pvSystem pvSys;
} globals; } globals;
static void seqInitPvt(void *arg) static void seqInitPvt(void *arg)
...@@ -47,6 +48,22 @@ static void seqLazyInit() ...@@ -47,6 +48,22 @@ static void seqLazyInit()
epicsThreadOnce(&seqOnceFlag, seqInitPvt, NULL); epicsThreadOnce(&seqOnceFlag, seqInitPvt, NULL);
} }
void createOrAttachPvSystem(struct program_instance *sp)
{
seqLazyInit();
epicsMutexMustLock(globals.lock);
if (!pvSysIsDefined(globals.pvSys)) {
pvStat status = pvSysCreate(&globals.pvSys);
if (status != pvStatOK) {
errlogPrintf("getPvSystem: pvSysCreate() failure\n");
}
} else {
pvSysAttach(globals.pvSys);
}
sp->pvSys = globals.pvSys;
epicsMutexUnlock(globals.lock);
}
epicsShareFunc void seqRegisterSequencerProgram(seqProgram *prog) epicsShareFunc void seqRegisterSequencerProgram(seqProgram *prog)
{ {
struct sequencerProgram *sp = NULL; struct sequencerProgram *sp = NULL;
......
...@@ -46,7 +46,7 @@ static int findStateSet(SPROG *sp, void *param) ...@@ -46,7 +46,7 @@ static int findStateSet(SPROG *sp, void *param)
} }
/* /*
* seqFindStateSet() - find a state set in the state program list from thread id. * seqFindStateSet() - find a state set in the program list from thread id.
*/ */
SSCB *seqFindStateSet(epicsThreadId threadId) SSCB *seqFindStateSet(epicsThreadId threadId)
{ {
...@@ -93,23 +93,8 @@ static int addProg(SPROG **ppInstances, seqProgram *pseq, void *param) ...@@ -93,23 +93,8 @@ static int addProg(SPROG **ppInstances, seqProgram *pseq, void *param)
SPROG *sp = (SPROG *)param; SPROG *sp = (SPROG *)param;
if (!ppInstances || !pseq) { if (!ppInstances || !pseq) {
if (!pvSysIsDefined(sp->pvSys)) {
pvStat status = pvSysCreate(&sp->pvSys);
if (status != pvStatOK) {
errlogPrintf("pvSysCreate() failure\n");
}
}
return FALSE; return FALSE;
} }
if (!pvSysIsDefined(sp->pvSys)) {
SPROG *curSP;
foreach(curSP, *ppInstances) {
if (pvSysIsDefined(curSP->pvSys)) {
sp->pvSys = curSP->pvSys;
}
break;
}
}
/* same program name */ /* same program name */
if (strcmp(sp->progName, pseq->progName) == 0) { if (strcmp(sp->progName, pseq->progName) == 0) {
SPROG *curSP, *lastSP = NULL; SPROG *curSP, *lastSP = NULL;
...@@ -130,10 +115,9 @@ static int addProg(SPROG **ppInstances, seqProgram *pseq, void *param) ...@@ -130,10 +115,9 @@ static int addProg(SPROG **ppInstances, seqProgram *pseq, void *param)
} }
DEBUG("Added program %p, instance %d to instance list.\n", DEBUG("Added program %p, instance %d to instance list.\n",
sp, sp->instance); sp, sp->instance);
if (pvSysIsDefined(sp->pvSys)) return TRUE; /* terminate traversal */
return TRUE;
} }
return FALSE; return FALSE; /* continue traversal */
} }
/* /*
......
...@@ -28,10 +28,11 @@ void sequencer (void *arg) /* ptr to original (global) state program table */ ...@@ -28,10 +28,11 @@ void sequencer (void *arg) /* ptr to original (global) state program table */
/* Get this thread's id */ /* Get this thread's id */
sp->ss->threadId = epicsThreadGetIdSelf(); sp->ss->threadId = epicsThreadGetIdSelf();
/* Add the program to the state program list /* Add the program to the program list */
and if necessary create pvSys */
seqAddProg(sp); seqAddProg(sp);
createOrAttachPvSystem(sp);
if (!pvSysIsDefined(sp->pvSys)) if (!pvSysIsDefined(sp->pvSys))
{ {
sp->die = TRUE; sp->die = TRUE;
...@@ -262,7 +263,7 @@ static void ss_entry(void *arg) ...@@ -262,7 +263,7 @@ static void ss_entry(void *arg)
if (ss != sp->ss) if (ss != sp->ss)
{ {
ss->threadId = epicsThreadGetIdSelf(); ss->threadId = epicsThreadGetIdSelf();
pvSysAttach(sp->pvSys); createOrAttachPvSystem(sp);
} }
/* Register this thread with the EPICS watchdog (no callback func) */ /* Register this thread with the EPICS watchdog (no callback func) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment