add Timer::close()

An aid to orderly shutdown
This commit is contained in:
Michael Davidsaver
2018-04-02 12:25:46 -07:00
parent 87ade13234
commit 7b8ef390ce
2 changed files with 8 additions and 0 deletions

View File

@@ -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.

View File

@@ -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();