mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
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
This commit is contained in:
parent
3516a31eaa
commit
fa70ccc6c4
2 changed files with 5 additions and 4 deletions
|
|
@ -9,13 +9,14 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
|
CScheduler::CScheduler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CScheduler::~CScheduler()
|
CScheduler::~CScheduler()
|
||||||
{
|
{
|
||||||
assert(nThreadsServicingQueue == 0);
|
assert(nThreadsServicingQueue == 0);
|
||||||
|
if (stopWhenEmpty) assert(taskQueue.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,9 @@ private:
|
||||||
mutable Mutex newTaskMutex;
|
mutable Mutex newTaskMutex;
|
||||||
std::condition_variable newTaskScheduled;
|
std::condition_variable newTaskScheduled;
|
||||||
std::multimap<std::chrono::system_clock::time_point, Function> taskQueue GUARDED_BY(newTaskMutex);
|
std::multimap<std::chrono::system_clock::time_point, Function> taskQueue GUARDED_BY(newTaskMutex);
|
||||||
int nThreadsServicingQueue GUARDED_BY(newTaskMutex);
|
int nThreadsServicingQueue GUARDED_BY(newTaskMutex){0};
|
||||||
bool stopRequested GUARDED_BY(newTaskMutex);
|
bool stopRequested GUARDED_BY(newTaskMutex){false};
|
||||||
bool stopWhenEmpty GUARDED_BY(newTaskMutex);
|
bool stopWhenEmpty GUARDED_BY(newTaskMutex){false};
|
||||||
bool shouldStop() const EXCLUSIVE_LOCKS_REQUIRED(newTaskMutex) { return stopRequested || (stopWhenEmpty && taskQueue.empty()); }
|
bool shouldStop() const EXCLUSIVE_LOCKS_REQUIRED(newTaskMutex) { return stopRequested || (stopWhenEmpty && taskQueue.empty()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue