aboutsummaryrefslogtreecommitdiff
path: root/src/scheduler.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2015-05-15 12:40:36 -0400
committerGavin Andresen <gavinandresen@gmail.com>2015-05-16 17:59:23 -0400
commitf50105486f3a664c3ecd2d7a5552f2767941f4d7 (patch)
tree9297f7b38a0219abe9aef0706f597a7aef4b7da5 /src/scheduler.h
parente47c94e64c44e817ac80cf682a68ba0c4580952f (diff)
More robust CScheduler unit test
On a busy or slow system, the CScheduler unit test could fail because it assumed all threads would be done after a couple of milliseconds. Replace the hard-coded sleep with CScheduler stop() method that will cleanly exit the servicing threads when all tasks are completely finished.
Diffstat (limited to 'src/scheduler.h')
-rw-r--r--src/scheduler.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/scheduler.h b/src/scheduler.h
index bb383ab9f9..436659e58b 100644
--- a/src/scheduler.h
+++ b/src/scheduler.h
@@ -60,11 +60,24 @@ public:
// and interrupted using boost::interrupt_thread
void serviceQueue();
+ // Tell any threads running serviceQueue to stop as soon as they're
+ // done servicing whatever task they're currently servicing (drain=false)
+ // or when there is no work left to be done (drain=true)
+ void stop(bool drain=false);
+
+ // Returns number of tasks waiting to be serviced,
+ // and first and last task times
+ size_t getQueueInfo(boost::chrono::system_clock::time_point &first,
+ boost::chrono::system_clock::time_point &last) const;
+
private:
std::multimap<boost::chrono::system_clock::time_point, Function> taskQueue;
boost::condition_variable newTaskScheduled;
- boost::mutex newTaskMutex;
+ mutable boost::mutex newTaskMutex;
int nThreadsServicingQueue;
+ bool stopRequested;
+ bool stopWhenEmpty;
+ bool shouldStop() { return stopRequested || (stopWhenEmpty && taskQueue.empty()); }
};
#endif