From 8426a4dc7789d9095c9b28bdb9d0855d8e37b373 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 7 Nov 2018 22:59:30 -0800 Subject: [PATCH] libstrat: Use iterators when looping deferred waitables --- .../include/stratosphere/waitable_manager.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/stratosphere/libstratosphere/include/stratosphere/waitable_manager.hpp b/stratosphere/libstratosphere/include/stratosphere/waitable_manager.hpp index 569817c6b..c47ce81e3 100644 --- a/stratosphere/libstratosphere/include/stratosphere/waitable_manager.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/waitable_manager.hpp @@ -160,12 +160,12 @@ class WaitableManager : public SessionManagerBase { { std::scoped_lock lk{this_ptr->deferred_lock}; - for (size_t i = 0; i < this_ptr->deferred_waitables.size(); i++) { - auto w = this_ptr->deferred_waitables[i]; + for (auto it = this_ptr->deferred_waitables.begin(); it != this_ptr->deferred_waitables.end();) { + auto w = *it; Result rc = w->HandleDeferred(); if (rc == 0xF601 || !w->IsDeferred()) { - /* Remove from the deferred list. */ - this_ptr->deferred_waitables.erase(this_ptr->deferred_waitables.begin() + i); + /* Remove from the deferred list, set iterator. */ + it = this_ptr->deferred_waitables.erase(it); if (rc == 0xF601) { /* Delete the closed waitable. */ delete w; @@ -173,8 +173,9 @@ class WaitableManager : public SessionManagerBase { /* Add to the waitables list. */ this_ptr->AddWaitable(w); } - /* Subtract one from i, to avoid skipping a deferred session. */ - i--; + } else { + /* Move on to the next deferred waitable. */ + it++; } } }