Internal change

PiperOrigin-RevId: 495163109
This commit is contained in:
Hadon Nash 2022-12-13 16:58:12 -08:00 committed by Copybara-Service
parent 904a537b02
commit b9d020cb7d
2 changed files with 9 additions and 4 deletions

View File

@ -117,7 +117,7 @@ void Scheduler::SubmitWaitingTasksOnQueues() {
// Note: state_mutex_ is held when this function is entered or // Note: state_mutex_ is held when this function is entered or
// exited. // exited.
void Scheduler::HandleIdle() { void Scheduler::HandleIdle() {
if (handling_idle_) { if (++handling_idle_ > 1) {
// Someone is already inside this method. // Someone is already inside this method.
// Note: This can happen in the sections below where we unlock the mutex // Note: This can happen in the sections below where we unlock the mutex
// and make more nodes runnable: the nodes can run and become idle again // and make more nodes runnable: the nodes can run and become idle again
@ -127,7 +127,6 @@ void Scheduler::HandleIdle() {
VLOG(2) << "HandleIdle: already in progress"; VLOG(2) << "HandleIdle: already in progress";
return; return;
} }
handling_idle_ = true;
while (IsIdle() && (state_ == STATE_RUNNING || state_ == STATE_CANCELLING)) { while (IsIdle() && (state_ == STATE_RUNNING || state_ == STATE_CANCELLING)) {
// Remove active sources that are closed. // Remove active sources that are closed.
@ -165,11 +164,17 @@ void Scheduler::HandleIdle() {
} }
} }
// If HandleIdle has been called again, then continue scheduling.
if (handling_idle_ > 1) {
handling_idle_ = 1;
continue;
}
// Nothing left to do. // Nothing left to do.
break; break;
} }
handling_idle_ = false; handling_idle_ = 0;
} }
// Note: state_mutex_ is held when this function is entered or exited. // Note: state_mutex_ is held when this function is entered or exited.

View File

@ -302,7 +302,7 @@ class Scheduler {
// - We need it to be reentrant, which Mutex does not support. // - We need it to be reentrant, which Mutex does not support.
// - We want simultaneous calls to return immediately instead of waiting, // - We want simultaneous calls to return immediately instead of waiting,
// and Mutex's TryLock is not guaranteed to work. // and Mutex's TryLock is not guaranteed to work.
bool handling_idle_ ABSL_GUARDED_BY(state_mutex_) = false; int handling_idle_ ABSL_GUARDED_BY(state_mutex_) = 0;
// Mutex for the scheduler state and related things. // Mutex for the scheduler state and related things.
// Note: state_ is declared as atomic so that its getter methods don't need // Note: state_ is declared as atomic so that its getter methods don't need