Skip to content

Commit 1f668b6

Browse files
committed
Expose if CScheduler is being serviced, assert its not in EmptyQueue
1 parent 3192975 commit 1f668b6

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
@@ -140,6 +140,10 @@ size_t CScheduler::getQueueInfo(boost::chrono::system_clock::time_point &first,
140140
return result;
141141
}
142142

143+
bool CScheduler::AreThreadsServicingQueue() const {
144+
return nThreadsServicingQueue;
145+
}
146+
143147

144148
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
145149
{
@@ -193,6 +197,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void (void)>
193197
}
194198

195199
void SingleThreadedSchedulerClient::EmptyQueue() {
200+
assert(!m_pscheduler->AreThreadsServicingQueue());
196201
bool should_continue = true;
197202
while (should_continue) {
198203
ProcessQueue();

src/scheduler.h

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

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

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

0 commit comments

Comments
 (0)