From fa70ccc6c4e304646b4610228f3975b3a9762643 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 6 Mar 2020 17:35:09 -0500 Subject: scheduler: Use C++11 member initialization, add shutdown assert "Initializing the members in the declaration makes it easy to spot uninitialized ones". https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#c-data-structures --- src/scheduler.cpp | 3 ++- src/scheduler.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 7cb7754fde..67e17d074b 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -9,13 +9,14 @@ #include #include -CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false) +CScheduler::CScheduler() { } CScheduler::~CScheduler() { assert(nThreadsServicingQueue == 0); + if (stopWhenEmpty) assert(taskQueue.empty()); } diff --git a/src/scheduler.h b/src/scheduler.h index 4d5aa3068e..71d1726c4f 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -86,9 +86,9 @@ private: mutable Mutex newTaskMutex; std::condition_variable newTaskScheduled; std::multimap taskQueue GUARDED_BY(newTaskMutex); - int nThreadsServicingQueue GUARDED_BY(newTaskMutex); - bool stopRequested GUARDED_BY(newTaskMutex); - bool stopWhenEmpty GUARDED_BY(newTaskMutex); + int nThreadsServicingQueue GUARDED_BY(newTaskMutex){0}; + bool stopRequested GUARDED_BY(newTaskMutex){false}; + bool stopWhenEmpty GUARDED_BY(newTaskMutex){false}; bool shouldStop() const EXCLUSIVE_LOCKS_REQUIRED(newTaskMutex) { return stopRequested || (stopWhenEmpty && taskQueue.empty()); } }; -- cgit v1.2.3