diff --git a/src/remote/simpleChannelSearchManagerImpl.cpp b/src/remote/simpleChannelSearchManagerImpl.cpp index 4f4a771..587859e 100644 --- a/src/remote/simpleChannelSearchManagerImpl.cpp +++ b/src/remote/simpleChannelSearchManagerImpl.cpp @@ -15,6 +15,7 @@ #include #include #include +#include using namespace std; using namespace epics::pvData; @@ -75,18 +76,17 @@ void SimpleChannelSearchManagerImpl::activate() // add some jitter so that all the clients do not send at the same time double period = ATOMIC_PERIOD + (rand() % (2*PERIOD_JITTER_MS+1) - PERIOD_JITTER_MS)/(double)1000; - Context::shared_pointer context = m_context.lock(); - if (context.get()) + Context::shared_pointer context(m_context.lock()); + if (context) context->getTimer()->schedulePeriodic(shared_from_this(), period, period); - - //new Thread(this, "pvAccess immediate-search").start(); } SimpleChannelSearchManagerImpl::~SimpleChannelSearchManagerImpl() { - // shared_from_this() is not allowed from destructor - // be sure to call cancel() first - // cancel(); + Lock guard(m_mutex); + if (!m_canceled.get()) { + LOG(logLevelWarn, "Logic error: SimpleChannelSearchManagerImpl destroyed w/o cancel()"); + } } void SimpleChannelSearchManagerImpl::cancel() @@ -97,8 +97,8 @@ void SimpleChannelSearchManagerImpl::cancel() return; m_canceled.set(); - Context::shared_pointer context = m_context.lock(); - if (context.get()) + Context::shared_pointer context(m_context.lock()); + if (context) context->getTimer()->cancel(shared_from_this()); } diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index 18ce6b1..6fe604d 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -2586,7 +2586,10 @@ public: // reads CIDs // TODO optimize - std::tr1::shared_ptr csm = _context.lock()->getChannelSearchManager(); + ClientContextImpl::shared_pointer context(_context.lock()); + if(!context) + return; + std::tr1::shared_ptr csm = context->getChannelSearchManager(); int16 count = payloadBuffer->getShort(); for (int i = 0; i < count; i++) {