From 7b8ef390ce677b56afa7f30d56db7f03dc927080 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 2 Apr 2018 12:25:46 -0700 Subject: [PATCH] add Timer::close() An aid to orderly shutdown --- src/misc/pv/timer.h | 2 ++ src/misc/timer.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/misc/pv/timer.h b/src/misc/pv/timer.h index 8d1f802..be87b92 100644 --- a/src/misc/pv/timer.h +++ b/src/misc/pv/timer.h @@ -75,6 +75,8 @@ public: */ Timer(std::string threadName, ThreadPriority priority); virtual ~Timer(); + //! Prevent new callbacks from being scheduled, and cancel pending callbacks + void close(); /** * schedule a callback after a delay. * @param timerCallback the timerCallback instance. diff --git a/src/misc/timer.cpp b/src/misc/timer.cpp index de9587d..105d491 100644 --- a/src/misc/timer.cpp +++ b/src/misc/timer.cpp @@ -160,8 +160,14 @@ void Timer::run() } Timer::~Timer() { + close(); +} + +void Timer::close() { { Lock xx(mutex); + if(!alive) + return; // already closed alive = false; } waitForWork.signal();