Skip to content

Commit fa70ccc

Browse files
author
MarcoFalke
committed
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
1 parent 3516a31 commit fa70ccc

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/scheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#include <assert.h>
1010
#include <utility>
1111

12-
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
12+
CScheduler::CScheduler()
1313
{
1414
}
1515

1616
CScheduler::~CScheduler()
1717
{
1818
assert(nThreadsServicingQueue == 0);
19+
if (stopWhenEmpty) assert(taskQueue.empty());
1920
}
2021

2122

src/scheduler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class CScheduler
8686
mutable Mutex newTaskMutex;
8787
std::condition_variable newTaskScheduled;
8888
std::multimap<std::chrono::system_clock::time_point, Function> taskQueue GUARDED_BY(newTaskMutex);
89-
int nThreadsServicingQueue GUARDED_BY(newTaskMutex);
90-
bool stopRequested GUARDED_BY(newTaskMutex);
91-
bool stopWhenEmpty GUARDED_BY(newTaskMutex);
89+
int nThreadsServicingQueue GUARDED_BY(newTaskMutex){0};
90+
bool stopRequested GUARDED_BY(newTaskMutex){false};
91+
bool stopWhenEmpty GUARDED_BY(newTaskMutex){false};
9292
bool shouldStop() const EXCLUSIVE_LOCKS_REQUIRED(newTaskMutex) { return stopRequested || (stopWhenEmpty && taskQueue.empty()); }
9393
};
9494

0 commit comments

Comments
 (0)