diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2017-03-24 18:25:16 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2017-03-24 18:25:16 -0400 |
commit | 2fe4f6b9187d9153e335bf54ea43fc89a7987459 (patch) | |
tree | 8cb9d97062cdc67bc6a8f277a7735788a2e5375a /indra | |
parent | 7af4a49835880fc92461882d5354c0ff12a9672a (diff) |
MAINT-6789: Add LLEventThrottle::getInterval(), setInterval()
plus LLEventBatch::getSize(), setSize()
plus LLEventThrottle::getPostCount() and getDelay().
The interesting thing about LLEventThrottle::setInterval() and
LLEventBatch::setSize() is that either might cause an immediate flush().
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llcommon/lleventfilter.cpp | 49 | ||||
-rw-r--r-- | indra/llcommon/lleventfilter.h | 14 |
2 files changed, 63 insertions, 0 deletions
diff --git a/indra/llcommon/lleventfilter.cpp b/indra/llcommon/lleventfilter.cpp index 1fd29ea9e5..87eb583cb6 100644 --- a/indra/llcommon/lleventfilter.cpp +++ b/indra/llcommon/lleventfilter.cpp @@ -198,6 +198,16 @@ bool LLEventBatch::post(const LLSD& event) return false; } +void LLEventBatch::setSize(std::size_t size) +{ + mBatchSize = size; + // changing the size might mean that we have to flush NOW + if (mBatch.size() >= mBatchSize) + { + flush(); + } +} + LLEventThrottle::LLEventThrottle(F32 interval): LLEventFilter("throttle"), mInterval(interval), @@ -264,6 +274,45 @@ bool LLEventThrottle::post(const LLSD& event) mAlarm.actionAfter(timeRemaining, boost::bind(&LLEventThrottle::flush, this)); } } + return false; +} + +void LLEventThrottle::setInterval(F32 interval) +{ + F32 oldInterval = mInterval; + mInterval = interval; + // If we are not now within oldInterval of the last flush(), we're done: + // this will only affect behavior starting with the next flush(). + F32 timeRemaining = mTimer.getRemainingTimeF32(); + if (timeRemaining) + { + // We are currently within oldInterval of the last flush(). Figure out + // how much time remains until (the new) mInterval of the last + // flush(). Bt we don't actually store a timestamp for the last + // flush(); it's implicit. There are timeRemaining seconds until what + // used to be the end of the interval. Move that endpoint by the + // difference between the new interval and the old. + timeRemaining += (mInterval - oldInterval); + // If we're called with a larger interval, the difference is positive + // and timeRemaining increases. + // If we're called with a smaller interval, the difference is negative + // and timeRemaining decreases. The interesting case is when it goes + // nonpositive: when the new interval means we can flush immediately. + if (timeRemaining <= 0.0f) + { + flush(); + } + else + { + // immediately reset mTimer + mTimer.setTimerExpirySec(timeRemaining); + // and if mAlarm is running, reset that too + if (mAlarm.running()) + { + mAlarm.actionAfter(timeRemaining, boost::bind(&LLEventThrottle::flush, this)); + } + } + } } LLEventBatchThrottle::LLEventBatchThrottle(F32 interval): diff --git a/indra/llcommon/lleventfilter.h b/indra/llcommon/lleventfilter.h index 1445b8a3b7..68890846a7 100644 --- a/indra/llcommon/lleventfilter.h +++ b/indra/llcommon/lleventfilter.h @@ -237,6 +237,10 @@ public: // accumulate an event and flush() when big enough virtual bool post(const LLSD& event); + // query or reset batch size + std::size_t getSize() const { return mBatchSize; } + void setSize(std::size_t size); + private: LLSD mBatch; std::size_t mBatchSize; @@ -289,6 +293,16 @@ public: // register an event, may be either passed through or deferred virtual bool post(const LLSD& event); + // query or reset interval + F32 getInterval() const { return mInterval; } + void setInterval(F32 interval); + + // deferred posts + std::size_t getPostCount() const { return mPosts; } + + // time until next event would be passed through, 0.0 if now + F32 getDelay() const { return mTimer.getRemainingTimeF32(); } + private: // remember throttle interval F32 mInterval; |