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().meow-7.2.2
parent
7af4a49835
commit
2fe4f6b918
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue