Skip to content

Commit be495b4

Browse files
TheBlueMattfurszy
authored andcommitted
Expose if CScheduler is being serviced, assert its not in EmptyQueue
1 parent 9b5ccee commit be495b4

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
@@ -122,6 +122,10 @@ size_t CScheduler::getQueueInfo(boost::chrono::system_clock::time_point &first,
122122
return result;
123123
}
124124

125+
bool CScheduler::AreThreadsServicingQueue() const {
126+
return nThreadsServicingQueue;
127+
}
128+
125129

126130
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
127131
{
@@ -175,6 +179,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void (void)>
175179
}
176180

177181
void SingleThreadedSchedulerClient::EmptyQueue() {
182+
assert(!m_pscheduler->AreThreadsServicingQueue());
178183
bool should_continue = true;
179184
while (should_continue) {
180185
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)