From b70c1d69a8f983e277e637102653b75cd89ac448 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Wed, 23 Mar 2016 23:15:29 +0100 Subject: [PATCH] ChannelProviderFactoryImpl static destruction fixed references #37 --- src/pva/clientFactory.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/pva/clientFactory.cpp b/src/pva/clientFactory.cpp index aeb644d..2e8cec8 100644 --- a/src/pva/clientFactory.cpp +++ b/src/pva/clientFactory.cpp @@ -16,21 +16,22 @@ using namespace epics::pvData; using namespace epics::pvAccess; -static Mutex cfact_mutex; -static ChannelProvider::shared_pointer cfact_shared_provider; - class ChannelProviderFactoryImpl : public ChannelProviderFactory { +private: + Mutex m_mutex; + ChannelProvider::shared_pointer m_shared_provider; + public: POINTER_DEFINITIONS(ChannelProviderFactoryImpl); virtual ~ChannelProviderFactoryImpl() { - Lock guard(cfact_mutex); - if (cfact_shared_provider) + Lock guard(m_mutex); + if (m_shared_provider) { ChannelProvider::shared_pointer provider; - cfact_shared_provider.swap(provider); + m_shared_provider.swap(provider); // factroy cleans up also shared provider provider->destroy(); } @@ -43,22 +44,23 @@ public: virtual ChannelProvider::shared_pointer sharedInstance() { - Lock guard(cfact_mutex); - if (!cfact_shared_provider) + Lock guard(m_mutex); + if (!m_shared_provider) { epics::pvAccess::Configuration::shared_pointer def; - cfact_shared_provider = createClientProvider(def); + m_shared_provider = createClientProvider(def); } - return cfact_shared_provider; + return m_shared_provider; } virtual ChannelProvider::shared_pointer newInstance(const std::tr1::shared_ptr& conf) { - Lock guard(cfact_mutex); + Lock guard(m_mutex); return createClientProvider(conf); } }; +static Mutex cprovfact_mutex; static ChannelProviderFactoryImpl::shared_pointer pva_factory; void ClientFactory::start() @@ -66,7 +68,7 @@ void ClientFactory::start() epicsSignalInstallSigAlarmIgnore(); epicsSignalInstallSigPipeIgnore(); - Lock guard(cfact_mutex); + Lock guard(cprovfact_mutex); if (!pva_factory) pva_factory.reset(new ChannelProviderFactoryImpl()); @@ -75,7 +77,7 @@ void ClientFactory::start() void ClientFactory::stop() { - Lock guard(cfact_mutex); + Lock guard(cprovfact_mutex); if (pva_factory) {