diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-05-03 08:52:32 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-05-03 08:52:32 -0400 |
commit | 9f620efa9dd60c5de6b7ea807d53bba922294726 (patch) | |
tree | f296457400e5edc4f50ba4a057d9fc81dcd1f5b9 | |
parent | 48e1979abaecc03af96e7e752e65c645083a4268 (diff) |
Make LLLater store target time in mHandles; ditch 2nd unordered_map.
Instead of maintaining a whole separate unordered_map to look up target times,
make room in the HandleMap entry for the target time. There's still
circularity, but the split into doAtTime1() and doAtTime2() resolves it: since
doAtTime2() accepts the mHandles iterator created by doAtTime1(), doAtTime2()
can simply store the new mQueue handle_type into the appropriate slot.
Also sprinkle in a few more override keywords for consistency.
-rw-r--r-- | indra/llcommon/llcallbacklist.cpp | 50 | ||||
-rw-r--r-- | indra/llcommon/llcallbacklist.h | 10 | ||||
-rw-r--r-- | indra/newview/llfloaterlinkreplace.h | 4 | ||||
-rw-r--r-- | indra/newview/llfloaterregionrestarting.h | 6 | ||||
-rw-r--r-- | indra/newview/llpanelpeople.cpp | 12 |
5 files changed, 38 insertions, 44 deletions
diff --git a/indra/llcommon/llcallbacklist.cpp b/indra/llcommon/llcallbacklist.cpp index 85c73fec8f..19b948a5e1 100644 --- a/indra/llcommon/llcallbacklist.cpp +++ b/indra/llcommon/llcallbacklist.cpp @@ -130,33 +130,34 @@ LLCallbackList::handle_t LLCallbackList::doOnIdleRepeating( const bool_func_t& f *****************************************************************************/ LLLater::LLLater() {} -LLLater::DoneMap::iterator LLLater::doAtTime1(LLDate::timestamp time) +LLLater::HandleMap::iterator LLLater::doAtTime1(LLDate::timestamp time) { // Pick token FIRST to store a self-reference in mQueue's managed node as // well as in mHandles. Pre-increment to distinguish 0 from any live // handle_t. token_t token{ ++mToken }; - auto [iter, inserted]{ mDoneTimes.emplace(token, time) }; + // For the moment, store a default-constructed mQueue handle -- + // doAtTime2() will fill in. + auto [iter, inserted]{ mHandles.emplace( + token, + HandleMap::mapped_type{ queue_t::handle_type(), time }) }; llassert(inserted); return iter; } -LLLater::handle_t LLLater::doAtTime2(nullary_func_t callable, DoneMap::iterator iter) +LLLater::handle_t LLLater::doAtTime2(nullary_func_t callable, HandleMap::iterator iter) { bool first{ mQueue.empty() }; - // DoneMap::iterator references (token, time) pair - auto handle{ mQueue.emplace(callable, iter->first, iter->second) }; - auto hiter{ mHandles.emplace(iter->first, handle).first }; - // When called by Periodic, we're passed an existing DoneMap entry, - // meaning the token already exists, meaning emplace() will tell us it - // found an existing entry rather than creating a new one. In that case, - // it's essential to update the handle. - hiter->second = handle; + // HandleMap::iterator references (token, (handle, time)) pair + auto handle{ mQueue.emplace(callable, iter->first, iter->second.second) }; + // Now that we have an mQueue handle_type, store it in mHandles entry. + iter->second.first = handle; if (first) { // If this is our first entry, register for regular callbacks. mLive = LLCallbackList::instance().doOnIdleRepeating([this]{ return tick(); }); } + // Make an LLLater::handle_t from token. return { iter->first }; } @@ -181,7 +182,7 @@ LLLater::handle_t LLLater::doAfterInterval(nullary_func_t callable, F32 seconds) struct LLLater::Periodic { LLLater* mLater; - DoneMap::iterator mDone; + HandleMap::iterator mHandleEntry; bool_func_t mCallable; F32 mSeconds; @@ -193,9 +194,10 @@ struct LLLater::Periodic // Don't call doAfterInterval(), which rereads LLDate::now(), // since that would defer by however long it took us to wake // up and notice plus however long callable() took to run. - // Bump our mDoneTimes entry so getRemaining() can track. - mDone->second += mSeconds; - mLater->doAtTime2(*this, mDone); + // Bump the time in our mHandles entry so getRemaining() can see. + // HandleMap::iterator references (token, (handle, time)) pair. + mHandleEntry->second.second += mSeconds; + mLater->doAtTime2(*this, mHandleEntry); } } }; @@ -207,7 +209,7 @@ LLLater::handle_t LLLater::doPeriodically(bool_func_t callable, F32 seconds) llassert(seconds > 0); auto iter{ doAtTime1(LLDate::now().secondsSinceEpoch() + seconds) }; // The whole reason we split doAtTime() into doAtTime1() and doAtTime2() - // is to be able to bind the mDoneTimes entry into Periodic. + // is to be able to bind the mHandles entry into Periodic. return doAtTime2(Periodic{ this, iter, callable, seconds }, iter); } @@ -220,14 +222,15 @@ bool LLLater::isRunning(handle_t timer) const F32 LLLater::getRemaining(handle_t timer) const { - auto found{ mDoneTimes.find(timer.token) }; - if (found == mDoneTimes.end()) + auto found{ mHandles.find(timer.token) }; + if (found == mHandles.end()) { return 0.f; } else { - return found->second - LLDate::now().secondsSinceEpoch(); + // HandleMap::iterator references (token, (handle, time)) pair + return found->second.second - LLDate::now().secondsSinceEpoch(); } } @@ -270,12 +273,11 @@ bool LLLater::cancel(const handle_t& timer) return false; } - // erase from mQueue the handle_t referenced by timer.token - mQueue.erase(found->second); + // HandleMap::iterator references (token, (handle, time)) pair. + // Erase from mQueue the handle_type referenced by timer.token. + mQueue.erase(found->second.first); // before erasing timer.token from mHandles mHandles.erase(found); - // don't forget to erase mDoneTimes entry - mDoneTimes.erase(timer.token); if (mQueue.empty()) { // If that was the last active timer, unregister for callbacks. @@ -318,8 +320,6 @@ bool LLLater::tick() auto current{ top }; // remove the mHandles entry referencing this task mHandles.erase(current.mToken); - // and the mDoneTimes entry - mDoneTimes.erase(current.mToken); // before removing the mQueue task entry itself mQueue.pop(); // okay, NOW run diff --git a/indra/llcommon/llcallbacklist.h b/indra/llcommon/llcallbacklist.h index 17adb7f431..3ff1aad04e 100644 --- a/indra/llcommon/llcallbacklist.h +++ b/indra/llcommon/llcallbacklist.h @@ -241,10 +241,10 @@ private: // the heap aka priority queue queue_t mQueue; // handles we've returned that haven't yet canceled - using HandleMap = std::unordered_map<token_t, queue_t::handle_type>; + using HandleMap = std::unordered_map< + token_t, + std::pair<queue_t::handle_type, LLDate::timestamp>>; HandleMap mHandles; - using DoneMap = std::unordered_map<token_t, LLDate::timestamp>; - DoneMap mDoneTimes; token_t mToken{ 0 }; // While mQueue is non-empty, register for regular callbacks. LLCallbackList::temp_handle_t mLive; @@ -252,8 +252,8 @@ private: struct Periodic; // internal implementation for doAtTime() - DoneMap::iterator doAtTime1(LLDate::timestamp time); - handle_t doAtTime2(nullary_func_t callable, DoneMap::iterator iter); + HandleMap::iterator doAtTime1(LLDate::timestamp time); + handle_t doAtTime2(nullary_func_t callable, HandleMap::iterator iter); }; /*-------------------- legacy names in global namespace --------------------*/ diff --git a/indra/newview/llfloaterlinkreplace.h b/indra/newview/llfloaterlinkreplace.h index 8d91187a33..a11e025a71 100644 --- a/indra/newview/llfloaterlinkreplace.h +++ b/indra/newview/llfloaterlinkreplace.h @@ -86,8 +86,8 @@ public: LLFloaterLinkReplace(const LLSD& key); virtual ~LLFloaterLinkReplace(); - BOOL postBuild(); - virtual void onOpen(const LLSD& key); + BOOL postBuild() override; + void onOpen(const LLSD& key) override; bool tick() override; diff --git a/indra/newview/llfloaterregionrestarting.h b/indra/newview/llfloaterregionrestarting.h index d254149e30..6d3639c40c 100644 --- a/indra/newview/llfloaterregionrestarting.h +++ b/indra/newview/llfloaterregionrestarting.h @@ -42,10 +42,10 @@ public: private: LLFloaterRegionRestarting(const LLSD& key); virtual ~LLFloaterRegionRestarting(); - virtual BOOL postBuild(); + BOOL postBuild() override; bool tick() override; - virtual void refresh(); - virtual void draw(); + void refresh() override; + void draw() override; virtual void regionChange(); std::string mName; diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index ab79442f51..8efaab034b 100644 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -312,11 +312,6 @@ public: { stop(); } - - bool tick() override // from LLEventTimer - { - return false; - } }; /** @@ -353,7 +348,7 @@ public: LLAvatarTracker::instance().removeObserver(this); } - /*virtual*/ void changed(U32 mask) + void changed(U32 mask) override { if (mIsActive) { @@ -383,8 +378,7 @@ public: return false; } - // virtual - void setActive(bool active) + void setActive(bool active) override { mIsActive = active; if (active) @@ -493,7 +487,7 @@ public: setActive(false); } - /*virtual*/ void setActive(bool val) + void setActive(bool val) override { if (val) { |