diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-05-02 21:13:28 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-05-02 21:13:28 -0400 |
commit | c231c97eeefc484b74198ba86251054b7dc0e6bb (patch) | |
tree | abf1a5e08311cf3bb816c49778aa10a2ab02fc7e /indra/newview | |
parent | 9bf5fcd225ada9dcd63fc5710f58013e7839df09 (diff) |
WIP: In llcallbacklist.h, add singleton LLLater for time delays.
The big idea is to reduce the number of per-tick callbacks asking, "Is it time
yet? Is it time yet?" We do that for LLEventTimer and LLEventTimeout.
LLLater presents doAtTime(LLDate), with doAfterInterval() and doPeriodically()
methods implemented using doAtTime(). All return handles. The free functions
doAfterInterval() and doPeriodically() now forward to the corresponding
LLLater methods.
LLLater also presents isRunning(handle) and cancel(handle).
LLLater borrows the tactic of LLEventTimer: while there's at least one running
timer, it registers an LLCallbackList tick() callback to service ready timers.
But instead of looping over all of them asking, "Are you ready?" it keeps them
in a priority queue ordered by desired timestamp, and only touches those whose
timestamp has been reached. Also, it honors a maximum time slice: once the
ready timers have run for longer than the limit, it defers processing other
ready timers to the next tick() call. The intent is to consume fewer cycles
per tick() call, both by the management machinery and the timers themselves.
Revamp LLCallbackList to accept C++ callables in addition to (classic C
function pointer, void*) pairs. Make addFunction() return a handle (different
than LLLater handles) that can be passed to a new deleteFunction() overload,
since std::function instances can't be compared for equality.
In fact, implement LLCallbackList using boost::signals2::signal, which provides
almost exactly what we want.
LLCallbackList continues to accept (function pointer, void*) pairs, but now
we store a lambda that calls the function pointer with that void*. It takes
less horsing around to create a C++ callable from a (function pointer, void*)
pair than the other way around. For containsFunction() and deleteFunction(),
such pairs are the keys for a lookup table whose values are handles.
Instead of having a static global LLCallbackList gIdleCallbacks, make
LLCallbackList an LLSingleton to guarantee initialization. For backwards
compatibility, gIdleCallbacks is now a macro for LLCallbackList::instance().
Move doOnIdleOneTime() and doOnIdleRepeating() functions to LLCallbackList
methods, but for backwards compatibility continue providing free functions.
Reimplement LLEventTimer using LLLater::doPeriodically(). One implication is
that LLEventTimer need no longer be derived from LLInstanceTracker, which we
used to iterate over all instances every tick. Give it start() and stop()
methods, since some subclasses (e.g. LLFlashTimer) used to call its member
LLTimer's start() and stop(). Remove updateClass():
LLCallbackList::callFunctions() now takes care of that.
Remove LLToastLifeTimer::start() and stop(), since LLEventTimer now provides
those. Remove getRemainingTimeF32(), since LLLater does not (yet) provide that
feature.
While at it, make LLEventTimer::tick() return bool instead of BOOL, and change
existing overrides.
Make LLApp::stepFrame() call LLCallbackList::callFunctions() instead of
LLEventTimer::updateClass().
We could have refactored LLEventTimer to use the mechanism now built into
LLLater, but frankly the LLEventTimer API is rather clumsy. You MUST derive a
subclass and override tick(), and you must instantiate your subclass on the
heap because, when your tick() override returns false, LLEventTimer deletes
its subclass instance. The LLLater API is simpler to use, and LLEventTimer is
much simplified by using it.
Merge lleventfilter.h's LLEventTimeoutBase into LLEventTimeout, and likewise
merge LLEventThrottleBase into LLEventThrottle. The separation was for
testability, but now that they're no longer based on LLTimer, it becomes
harder to use dummy time for testing. Temporarily skip tests based on
LLEventTimeoutBase and LLEventThrottleBase.
Instead of listening for LLEventPump("mainloop") ticks and using LLTimer,
LLEventTimeout now uses LLLater::doAfterInterval(). Instead of LLTimer and
LLEventTimeout, LLEventThrottle likewise now uses LLLater::doAfterInterval().
Recast a couple local LLEventTimeout pre-lambda callable classes with lambdas.
Dignify F64 with a new typedef LLDate::timestamp. LLDate heavily depends on
that as its base time representation, but there are those who question use of
floating-point for time. This is a step towards insulating us from any future
change.
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llappearancemgr.cpp | 5 | ||||
-rw-r--r-- | indra/newview/lldonotdisturbnotificationstorage.h | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterlinkreplace.h | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterpreference.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterregionrestarting.h | 2 | ||||
-rw-r--r-- | indra/newview/llfloateruipreview.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llimview.h | 2 | ||||
-rw-r--r-- | indra/newview/lllocalbitmaps.h | 2 | ||||
-rw-r--r-- | indra/newview/lllocalgltfmaterials.h | 2 | ||||
-rw-r--r-- | indra/newview/llmediadataclient.h | 10 | ||||
-rw-r--r-- | indra/newview/llpanelpeople.cpp | 6 | ||||
-rw-r--r-- | indra/newview/llsetkeybinddialog.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llspeakers.h | 2 | ||||
-rw-r--r-- | indra/newview/lltoast.cpp | 29 | ||||
-rw-r--r-- | indra/newview/lltoast.h | 10 | ||||
-rw-r--r-- | indra/newview/llviewermessage.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llviewerparcelmediaautoplay.h | 2 |
17 files changed, 35 insertions, 49 deletions
diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp index c84657cf7a..7e84ad3b2a 100644 --- a/indra/newview/llappearancemgr.cpp +++ b/indra/newview/llappearancemgr.cpp @@ -123,8 +123,7 @@ public: stop(); } - /*virtual*/ - BOOL tick() + bool tick() override { if(mEventTimer.hasExpired()) { @@ -332,7 +331,7 @@ public: // virtual // Will be deleted after returning true - only safe to do this if all callbacks have fired. - BOOL tick() + bool tick() override { // mPendingRequests will be zero if all requests have been // responded to. mWaitTimes.empty() will be true if we have diff --git a/indra/newview/lldonotdisturbnotificationstorage.h b/indra/newview/lldonotdisturbnotificationstorage.h index 237d58b4de..2d39b5efed 100644 --- a/indra/newview/lldonotdisturbnotificationstorage.h +++ b/indra/newview/lldonotdisturbnotificationstorage.h @@ -42,7 +42,7 @@ public: ~LLDoNotDisturbNotificationStorageTimer(); public: - BOOL tick(); + bool tick() override; }; class LLDoNotDisturbNotificationStorage : public LLParamSingleton<LLDoNotDisturbNotificationStorage>, public LLNotificationStorage diff --git a/indra/newview/llfloaterlinkreplace.h b/indra/newview/llfloaterlinkreplace.h index 060773f93e..8d91187a33 100644 --- a/indra/newview/llfloaterlinkreplace.h +++ b/indra/newview/llfloaterlinkreplace.h @@ -89,7 +89,7 @@ public: BOOL postBuild(); virtual void onOpen(const LLSD& key); - virtual BOOL tick(); + bool tick() override; private: void checkEnableStart(); diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index a3e173398f..34dc263519 100644 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -1960,7 +1960,7 @@ public: protected: - BOOL tick() + bool tick() override { mCallback(mNewValue); mEventTimer.stop(); diff --git a/indra/newview/llfloaterregionrestarting.h b/indra/newview/llfloaterregionrestarting.h index 46416db2c8..d254149e30 100644 --- a/indra/newview/llfloaterregionrestarting.h +++ b/indra/newview/llfloaterregionrestarting.h @@ -43,7 +43,7 @@ private: LLFloaterRegionRestarting(const LLSD& key); virtual ~LLFloaterRegionRestarting(); virtual BOOL postBuild(); - virtual BOOL tick(); + bool tick() override; virtual void refresh(); virtual void draw(); virtual void regionChange(); diff --git a/indra/newview/llfloateruipreview.cpp b/indra/newview/llfloateruipreview.cpp index 553d09bec2..6da380c639 100644 --- a/indra/newview/llfloateruipreview.cpp +++ b/indra/newview/llfloateruipreview.cpp @@ -254,7 +254,7 @@ class LLFadeEventTimer : public LLEventTimer { public: LLFadeEventTimer(F32 refresh, LLGUIPreviewLiveFile* parent); - BOOL tick(); + bool tick() override; LLGUIPreviewLiveFile* mParent; private: BOOL mFadingOut; // fades in then out; this is toggled in between diff --git a/indra/newview/llimview.h b/indra/newview/llimview.h index bace97d37a..f0e3e26a86 100644 --- a/indra/newview/llimview.h +++ b/indra/newview/llimview.h @@ -51,7 +51,7 @@ class LLSessionTimeoutTimer : public LLEventTimer public: LLSessionTimeoutTimer(const LLUUID& session_id, F32 period) : LLEventTimer(period), mSessionId(session_id) {} virtual ~LLSessionTimeoutTimer() {}; - /* virtual */ BOOL tick(); + bool tick() override; private: LLUUID mSessionId; diff --git a/indra/newview/lllocalbitmaps.h b/indra/newview/lllocalbitmaps.h index 1fdf9dccbf..8420049b1e 100644 --- a/indra/newview/lllocalbitmaps.h +++ b/indra/newview/lllocalbitmaps.h @@ -121,7 +121,7 @@ class LLLocalBitmapTimer : public LLEventTimer void startTimer(); void stopTimer(); bool isRunning(); - BOOL tick(); + bool tick() override; }; diff --git a/indra/newview/lllocalgltfmaterials.h b/indra/newview/lllocalgltfmaterials.h index 13b7577e96..53639dfb1d 100644 --- a/indra/newview/lllocalgltfmaterials.h +++ b/indra/newview/lllocalgltfmaterials.h @@ -90,7 +90,7 @@ public: void startTimer(); void stopTimer(); bool isRunning(); - BOOL tick(); + bool tick() override; }; class LLLocalGLTFMaterialMgr : public LLSingleton<LLLocalGLTFMaterialMgr> diff --git a/indra/newview/llmediadataclient.h b/indra/newview/llmediadataclient.h index 8cd4793106..428e85b976 100644 --- a/indra/newview/llmediadataclient.h +++ b/indra/newview/llmediadataclient.h @@ -219,13 +219,13 @@ protected: { public: RetryTimer(F32 time, Request::ptr_t); - virtual BOOL tick(); + virtual bool tick() override; private: // back-pointer Request::ptr_t mRequest; }; - - + + protected: typedef std::list<Request::ptr_t> request_queue_t; typedef std::set<Request::ptr_t> request_set_t; @@ -286,12 +286,12 @@ private: { public: QueueTimer(F32 time, LLMediaDataClient *mdc); - virtual BOOL tick(); + bool tick() override; private: // back-pointer LLPointer<LLMediaDataClient> mMDC; }; - + void setIsRunning(bool val) { mQueueTimerIsRunning = val; } bool mQueueTimerIsRunning; diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index 13b52e97c5..aad6ceecb2 100644 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -313,7 +313,7 @@ public: mEventTimer.stop(); } - virtual BOOL tick() // from LLEventTimer + virtual bool tick() override // from LLEventTimer { return FALSE; } @@ -367,7 +367,7 @@ public: } - /*virtual*/ BOOL tick() + bool tick() override { if (!mIsActive) return FALSE; @@ -508,7 +508,7 @@ public: } } - /*virtual*/ BOOL tick() + bool tick() override { update(); return FALSE; diff --git a/indra/newview/llsetkeybinddialog.cpp b/indra/newview/llsetkeybinddialog.cpp index 74844a80e8..79d03922cc 100644 --- a/indra/newview/llsetkeybinddialog.cpp +++ b/indra/newview/llsetkeybinddialog.cpp @@ -53,7 +53,7 @@ public: virtual ~Updater(){} protected: - BOOL tick() + bool tick() override { mCallback(mMask); // Deletes itseft after execution diff --git a/indra/newview/llspeakers.h b/indra/newview/llspeakers.h index 22c9481687..0242da1605 100644 --- a/indra/newview/llspeakers.h +++ b/indra/newview/llspeakers.h @@ -159,7 +159,7 @@ public: * * If action callback is not specified returns true. Instance will be deleted by LLEventTimer::updateClass(). */ - virtual BOOL tick(); + bool tick() override; /** * Clears the callback. diff --git a/indra/newview/lltoast.cpp b/indra/newview/lltoast.cpp index 223aaad811..d30e028d33 100644 --- a/indra/newview/lltoast.cpp +++ b/indra/newview/lltoast.cpp @@ -43,34 +43,21 @@ LLToastLifeTimer::LLToastLifeTimer(LLToast* toast, F32 period) { } -/*virtual*/ -BOOL LLToastLifeTimer::tick() -{ - if (mEventTimer.hasExpired()) - { - mToast->expire(); - } - return FALSE; -} - -void LLToastLifeTimer::stop() -{ - mEventTimer.stop(); -} - -void LLToastLifeTimer::start() +bool LLToastLifeTimer::tick() { - mEventTimer.start(); + mToast->expire(); + return false; } void LLToastLifeTimer::restart() { - mEventTimer.reset(); + // start() discards any previously-running mTimer + start(); } -BOOL LLToastLifeTimer::getStarted() +bool LLToastLifeTimer::getStarted() { - return mEventTimer.getStarted(); + return LLLater::instance.isRunning(mTimer); } void LLToastLifeTimer::setPeriod(F32 period) @@ -78,12 +65,14 @@ void LLToastLifeTimer::setPeriod(F32 period) mPeriod = period; } +/*==========================================================================*| F32 LLToastLifeTimer::getRemainingTimeF32() { F32 et = mEventTimer.getElapsedTimeF32(); if (!getStarted() || et > mPeriod) return 0.0f; return mPeriod - et; } +|*==========================================================================*/ //-------------------------------------------------------------------------- LLToast::Params::Params() diff --git a/indra/newview/lltoast.h b/indra/newview/lltoast.h index ab559f1e6f..49969ab70a 100644 --- a/indra/newview/lltoast.h +++ b/indra/newview/lltoast.h @@ -53,15 +53,13 @@ public: LLToastLifeTimer(LLToast* toast, F32 period); /*virtual*/ - BOOL tick(); - void stop(); - void start(); + bool tick() override; void restart(); - BOOL getStarted(); + bool getStarted(); void setPeriod(F32 period); - F32 getRemainingTimeF32(); +// F32 getRemainingTimeF32(); - LLTimer& getEventTimer() { return mEventTimer;} +// LLTimer& getEventTimer() { return mEventTimer;} private : LLToast* mToast; }; diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index ff2753d240..b65305337f 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -2890,7 +2890,7 @@ public: virtual ~LLPostTeleportNotifiers(); //function to be called at the supplied frequency - virtual BOOL tick(); + bool tick() override; }; LLPostTeleportNotifiers::LLPostTeleportNotifiers() : LLEventTimer( 2.0 ) diff --git a/indra/newview/llviewerparcelmediaautoplay.h b/indra/newview/llviewerparcelmediaautoplay.h index e83085dee0..9367c2a629 100644 --- a/indra/newview/llviewerparcelmediaautoplay.h +++ b/indra/newview/llviewerparcelmediaautoplay.h @@ -35,7 +35,7 @@ class LLViewerParcelMediaAutoPlay : LLEventTimer, public LLSingleton<LLViewerPar { LLSINGLETON(LLViewerParcelMediaAutoPlay); public: - virtual BOOL tick() override; + bool tick() override; static void playStarted(); private: |