summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/llcommon/lleventfilter.cpp35
-rw-r--r--indra/llcommon/lleventfilter.h30
2 files changed, 47 insertions, 18 deletions
diff --git a/indra/llcommon/lleventfilter.cpp b/indra/llcommon/lleventfilter.cpp
index ddd7d5547a..9fb18dc67d 100644
--- a/indra/llcommon/lleventfilter.cpp
+++ b/indra/llcommon/lleventfilter.cpp
@@ -206,10 +206,8 @@ void LLEventBatch::flush()
bool LLEventBatch::post(const LLSD& event)
{
mBatch.append(event);
- if (mBatch.size() >= mBatchSize)
- {
- flush();
- }
+ // calling setSize(same) performs the very check we want
+ setSize(mBatchSize);
return false;
}
@@ -377,12 +375,14 @@ F32 LLEventThrottle::timerGetRemaining() const
/*****************************************************************************
* LLEventBatchThrottle
*****************************************************************************/
-LLEventBatchThrottle::LLEventBatchThrottle(F32 interval):
- LLEventThrottle(interval)
+LLEventBatchThrottle::LLEventBatchThrottle(F32 interval, std::size_t size):
+ LLEventThrottle(interval),
+ mBatchSize(size)
{}
-LLEventBatchThrottle::LLEventBatchThrottle(LLEventPump& source, F32 interval):
- LLEventThrottle(source, interval)
+LLEventBatchThrottle::LLEventBatchThrottle(LLEventPump& source, F32 interval, std::size_t size):
+ LLEventThrottle(source, interval),
+ mBatchSize(size)
{}
bool LLEventBatchThrottle::post(const LLSD& event)
@@ -390,5 +390,22 @@ bool LLEventBatchThrottle::post(const LLSD& event)
// simply retrieve pending value and append the new event to it
LLSD partial = pending();
partial.append(event);
- return LLEventThrottle::post(partial);
+ bool ret = LLEventThrottle::post(partial);
+ // The post() call above MIGHT have called flush() already. If it did,
+ // then pending() was reset to empty. If it did not, though, but the batch
+ // size has grown to the limit, flush() anyway. If there's a limit at all,
+ // of course. Calling setSize(same) performs the very check we want.
+ setSize(mBatchSize);
+ return ret;
+}
+
+void LLEventBatchThrottle::setSize(std::size_t size)
+{
+ mBatchSize = size;
+ // Changing the size might mean that we have to flush NOW. Don't forget
+ // that 0 means unlimited.
+ if (mBatchSize && pending().size() >= mBatchSize)
+ {
+ flush();
+ }
}
diff --git a/indra/llcommon/lleventfilter.h b/indra/llcommon/lleventfilter.h
index cae18bfd86..ccbbc8bd25 100644
--- a/indra/llcommon/lleventfilter.h
+++ b/indra/llcommon/lleventfilter.h
@@ -270,14 +270,15 @@ private:
* For a deferred event, the LLSD blob delivered to listeners is from the most
* recent deferred post() call. However, a sender may obtain the previous
* event blob by calling pending(), modifying it as desired and post()ing the
- * new value. Each time an event is delivered to listeners, the pending()
- * value is reset to isUndefined().
+ * new value. (See LLEventBatchThrottle.) Each time an event is delivered to
+ * listeners, the pending() value is reset to isUndefined().
*
* You may also call flush() to immediately pass along any deferred events to
* all listeners.
*
* @NOTE This is an abstract base class so that, for testing, we can use an
- * alternate "timer" that doesn't actually consume real time.
+ * alternate "timer" that doesn't actually consume real time. See
+ * LLEventThrottle.
*/
class LL_COMMON_API LLEventThrottleBase: public LLEventFilter
{
@@ -348,20 +349,31 @@ private:
};
/**
- * LLEventBatchThrottle: like LLEventThrottle, it refuses to pass events to
- * listeners more often than once per specified time interval.
- * Like LLEventBatch, it accumulates pending events into an LLSD Array.
+ * LLEventBatchThrottle: like LLEventThrottle, it's reluctant to pass events
+ * to listeners more often than once per specified time interval -- but only
+ * reluctant, since exceeding the specified batch size limit can cause it to
+ * deliver accumulated events sooner. Like LLEventBatch, it accumulates
+ * pending events into an LLSD Array, optionally flushing when the batch grows
+ * to a certain size.
*/
class LLEventBatchThrottle: public LLEventThrottle
{
public:
- // pass time interval
- LLEventBatchThrottle(F32 interval);
+ // pass time interval and (optionally) max batch size; 0 means batch can
+ // grow arbitrarily large
+ LLEventBatchThrottle(F32 interval, std::size_t size = 0);
// construct and connect
- LLEventBatchThrottle(LLEventPump& source, F32 interval);
+ LLEventBatchThrottle(LLEventPump& source, F32 interval, std::size_t size = 0);
// append a new event to current batch
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:
+ std::size_t mBatchSize;
};
#endif /* ! defined(LL_LLEVENTFILTER_H) */