From b3ffc49f71339d1074aff45b5dea3f79ee64fb65 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 28 May 2018 07:49:59 -0700 Subject: [PATCH] pvalink: defer opening links until IOC running --- pdbApp/pvalink.cpp | 12 ++++++++++++ pdbApp/pvalink.h | 2 ++ pdbApp/pvalink_channel.cpp | 1 + pdbApp/pvalink_lset.cpp | 2 ++ 4 files changed, 17 insertions(+) diff --git a/pdbApp/pvalink.cpp b/pdbApp/pvalink.cpp index aebfa65..52cb888 100644 --- a/pdbApp/pvalink.cpp +++ b/pdbApp/pvalink.cpp @@ -115,6 +115,18 @@ void initPVALink(initHookState state) // after epicsExit(exitDatabase) // so hook registered here will be run before iocShutdown() epicsAtExit(stopPVAPool, NULL); + + Guard G(pvaGlobal->lock); + pvaGlobal->running = true; + + for(pvaGlobal_t::channels_t::iterator it(pvaGlobal->channels.begin()), end(pvaGlobal->channels.end()); + it != end; ++it) + { + std::tr1::shared_ptr chan(it->second.lock()); + if(!chan) continue; + + chan->open(); + } } } diff --git a/pdbApp/pvalink.h b/pdbApp/pvalink.h index 00392b3..39b2181 100644 --- a/pdbApp/pvalink.h +++ b/pdbApp/pvalink.h @@ -101,6 +101,8 @@ struct pvaGlobal_t { pvd::Mutex lock; + bool running; // set after dbEvent is initialized and safe to use + // a tuple of channel name and printed pvRequest (or Monitor) typedef std::pair channels_key_t; // pvaLinkChannel dtor prunes dead entires diff --git a/pdbApp/pvalink_channel.cpp b/pdbApp/pvalink_channel.cpp index 9d93d07..3d5c6f6 100644 --- a/pdbApp/pvalink_channel.cpp +++ b/pdbApp/pvalink_channel.cpp @@ -20,6 +20,7 @@ pvaGlobal_t::pvaGlobal_t() ,provider_remote("pva") ,create(pvd::getPVDataCreate()) ,queue("PVAL") + ,running(false) { // worker should be above PVA worker priority? queue.start(std::max(1, pvaLinkNWorkers), epicsThreadPriorityMedium); diff --git a/pdbApp/pvalink_lset.cpp b/pdbApp/pvalink_lset.cpp index 04e39e6..f6e1025 100644 --- a/pdbApp/pvalink_lset.cpp +++ b/pdbApp/pvalink_lset.cpp @@ -76,6 +76,8 @@ void pvaOpenLink(DBLINK *plink) pvaGlobal->channels.insert(std::make_pair(key, chan)); doOpen = true; } + + doOpen &= pvaGlobal->running; // if not running, then open from initHook } if(doOpen) {