Skip to content

Commit

Permalink
Expose if CScheduler is being serviced, assert its not in EmptyQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt authored and furszy committed Dec 17, 2020
1 parent 655d4ff commit c2ea44f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/scheduler.cpp
Expand Up @@ -122,6 +122,10 @@ size_t CScheduler::getQueueInfo(boost::chrono::system_clock::time_point &first,
return result;
}

bool CScheduler::AreThreadsServicingQueue() const {
return nThreadsServicingQueue;
}


void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
{
Expand Down Expand Up @@ -175,6 +179,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void (void)>
}

void SingleThreadedSchedulerClient::EmptyQueue() {
assert(!m_pscheduler->AreThreadsServicingQueue());
bool should_continue = true;
while (should_continue) {
ProcessQueue();
Expand Down
4 changes: 4 additions & 0 deletions src/scheduler.h
Expand Up @@ -72,6 +72,9 @@ class CScheduler
size_t getQueueInfo(boost::chrono::system_clock::time_point &first,
boost::chrono::system_clock::time_point &last) const;

// Returns true if there are threads actively running in serviceQueue()
bool AreThreadsServicingQueue() const;

private:
std::multimap<boost::chrono::system_clock::time_point, Function> taskQueue;
boost::condition_variable newTaskScheduled;
Expand Down Expand Up @@ -104,6 +107,7 @@ class SingleThreadedSchedulerClient {
void AddToProcessQueue(std::function<void (void)> func);

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

Expand Down

0 comments on commit c2ea44f

Please sign in to comment.