From dd78b467f8f6b57f71b0e75a2941047ad6d74f4e Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 30 May 2017 17:32:28 +0200 Subject: [PATCH] consolidate AtomicBoolean --- pvtoolsSrc/pvput.cpp | 33 +-------------------------------- src/pva/pv/pvaDefs.h | 23 +++++++++++++++++++++++ src/remote/pv/remote.h | 32 -------------------------------- 3 files changed, 24 insertions(+), 64 deletions(-) diff --git a/pvtoolsSrc/pvput.cpp b/pvtoolsSrc/pvput.cpp index 8608528..9eb9e89 100644 --- a/pvtoolsSrc/pvput.cpp +++ b/pvtoolsSrc/pvput.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -357,38 +358,6 @@ void printValue(std::string const & channelName, PVStructure::shared_pointer con std::cout << std::endl << *(pv.get()) << std::endl << std::endl; } -struct AtomicBoolean_null_deleter -{ - void operator()(void const *) const {} -}; - -// standard performance on set/clear, use of TR1::shared_ptr lock-free counter for get -// alternative is to use boost::atomic -class AtomicBoolean -{ -public: - AtomicBoolean() : counter(static_cast(0), AtomicBoolean_null_deleter()) {}; - - void set() { - mutex.lock(); - setp = counter; - mutex.unlock(); - } - void clear() { - mutex.lock(); - setp.reset(); - mutex.unlock(); - } - - bool get() const { - return counter.use_count() == 2; - } -private: - TR1::shared_ptr counter; - TR1::shared_ptr setp; - epics::pvData::Mutex mutex; -}; - class ChannelPutRequesterImpl : public ChannelPutRequester { private: diff --git a/src/pva/pv/pvaDefs.h b/src/pva/pv/pvaDefs.h index 6497d47..c88820e 100644 --- a/src/pva/pv/pvaDefs.h +++ b/src/pva/pv/pvaDefs.h @@ -17,6 +17,29 @@ typedef struct { typedef epicsInt32 pvAccessID; +class AtomicBoolean +{ +public: + AtomicBoolean() : val(false) {} + + void set() { + epicsGuard G(mutex); + val = true; + } + void clear() { + epicsGuard G(mutex); + val = false; + } + + bool get() const { + epicsGuard G(mutex); + return val; + } +private: + bool val; + mutable epicsMutex mutex; +}; + }} #endif // PVADEFS_H diff --git a/src/remote/pv/remote.h b/src/remote/pv/remote.h index 1e5d2ed..c0a35ee 100644 --- a/src/remote/pv/remote.h +++ b/src/remote/pv/remote.h @@ -609,38 +609,6 @@ public: }; -struct AtomicBoolean_null_deleter -{ - void operator()(void const *) const {} -}; - -// standard performance on set/clear, use of tr1::shared_ptr lock-free counter for get -// alternative is to use boost::atomic -class AtomicBoolean -{ -public: - AtomicBoolean() : counter(static_cast(0), AtomicBoolean_null_deleter()) {}; - - void set() { - mutex.lock(); - setp = counter; - mutex.unlock(); - } - void clear() { - mutex.lock(); - setp.reset(); - mutex.unlock(); - } - - bool get() const { - return counter.use_count() == 2; - } -private: - std::tr1::shared_ptr counter; - std::tr1::shared_ptr setp; - epics::pvData::Mutex mutex; -}; - } }