Improve deferral management logic, to fix order-sensitive bug

This commit is contained in:
Michael Scire 2019-01-21 22:28:04 -08:00
parent f9d38856f3
commit de4c2ddae1

View File

@ -182,7 +182,9 @@ class WaitableManager : public SessionManagerBase {
/* We finished processing, and maybe that means we can stop deferring an object. */ /* We finished processing, and maybe that means we can stop deferring an object. */
{ {
std::scoped_lock lk{this_ptr->deferred_lock}; std::scoped_lock lk{this_ptr->deferred_lock};
bool undeferred_any = true;
while (undeferred_any) {
undeferred_any = false;
for (auto it = this_ptr->deferred_waitables.begin(); it != this_ptr->deferred_waitables.end();) { for (auto it = this_ptr->deferred_waitables.begin(); it != this_ptr->deferred_waitables.end();) {
auto w = *it; auto w = *it;
Result rc = w->HandleDeferred(); Result rc = w->HandleDeferred();
@ -195,6 +197,7 @@ class WaitableManager : public SessionManagerBase {
} else { } else {
/* Add to the waitables list. */ /* Add to the waitables list. */
this_ptr->AddWaitable(w); this_ptr->AddWaitable(w);
undeferred_any = true;
} }
} else { } else {
/* Move on to the next deferred waitable. */ /* Move on to the next deferred waitable. */
@ -204,6 +207,7 @@ class WaitableManager : public SessionManagerBase {
} }
} }
} }
}
IWaitable *GetWaitable() { IWaitable *GetWaitable() {
std::scoped_lock lk{this->process_lock}; std::scoped_lock lk{this->process_lock};