Skip to content

Commit ee2c537

Browse files
TheBlueMattfurszy
authored andcommitted
Expose if CScheduler is being serviced, assert its not in EmptyQueue
1 parent 35f2fc8 commit ee2c537

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/scheduler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ size_t CScheduler::getQueueInfo(boost::chrono::system_clock::time_point &first,
121121
return result;
122122
}
123123

124+
bool CScheduler::AreThreadsServicingQueue() const {
125+
return nThreadsServicingQueue;
126+
}
127+
124128
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
125129
{
126130
LOCK(m_cs_callbacks_pending);
@@ -173,6 +177,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void (void)>
173177
}
174178

175179
void SingleThreadedSchedulerClient::EmptyQueue() {
180+
assert(!m_pscheduler->AreThreadsServicingQueue());
176181
bool should_continue = true;
177182
while (should_continue) {
178183
ProcessQueue();

src/scheduler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class CScheduler
7272
size_t getQueueInfo(boost::chrono::system_clock::time_point &first,
7373
boost::chrono::system_clock::time_point &last) const;
7474

75+
// Returns true if there are threads actively running in serviceQueue()
76+
bool AreThreadsServicingQueue() const;
77+
7578
private:
7679
std::multimap<boost::chrono::system_clock::time_point, Function> taskQueue;
7780
boost::condition_variable newTaskScheduled;
@@ -104,6 +107,7 @@ class SingleThreadedSchedulerClient {
104107
void AddToProcessQueue(std::function<void (void)> func);
105108

106109
// Processes all remaining queue members on the calling thread, blocking until queue is empty
110+
// Must be called after the CScheduler has no remaining processing threads!
107111
void EmptyQueue();
108112
};
109113

0 commit comments

Comments
 (0)