1#ifndef RESIP_TimeLimitFifo_hxx
2#define RESIP_TimeLimitFifo_hxx
23template<
typename Payload>
32 inline const Payload&
getMsg()
const {
return mMsg;}
33 inline void setMsg(
const Payload& pMsg) { mMsg = pMsg;}
34 inline const time_t&
getTime()
const {
return mTime;}
98 unsigned int maxSize);
210 time_t timeDepthInternal()
const;
215 time_t mMaxDurationSecs;
216 unsigned int mMaxSize;
217 unsigned int mUnreservedMaxSize;
222 unsigned int maxSize)
224 mMaxDurationSecs(maxDurationSecs),
226 mUnreservedMaxSize((int)((maxSize*8)/10))
241 Lock lock(mMutex); (void)lock;
243 if (wouldAcceptInteral(
usage))
248 mCondition.notify_one();
261 Lock lock(mMutex); (void)lock;
263 return wouldAcceptInteral(
usage);
295 return time(0) - mFifo.front().getTime();
300TimeLimitFifo<Msg>::wouldAcceptInteral(DepthUsage
usage)
const
302 if ((mMaxSize != 0 &&
303 mFifo.size() >= mMaxSize))
308 if (
usage == InternalElement)
313 if (mUnreservedMaxSize != 0 &&
314 mFifo.size() >= mUnreservedMaxSize)
319 if (
usage == IgnoreTimeDepth)
326 if (mFifo.size() == 0 ||
327 mMaxDurationSecs == 0 ||
328 timeDepthInternal() < mMaxDurationSecs)
340 Lock lock(mMutex); (void)lock;
341 return timeDepthInternal();
348 Lock lock(mMutex); (void)lock;
350 while (!mFifo.empty())
352 delete mFifo.front().getMsg();
368 return mUnreservedMaxSize;
382 return mMaxDurationSecs;
389 Lock lock(mMutex); (void)lock;
390 mUnreservedMaxSize=int(maxCount * 0.8);
397 Lock lock(mMutex); (void)lock;
399 mMaxDurationSecs=maxSecs;
#define resip_assert(x)
This file needs to work for both C and C++ code.
The base class from which various templated Fifo classes are derived.
virtual unsigned int size() const
get the current size of the fifo.
Condition mCondition
condition for waiting on new queue items
bool empty() const
is the queue empty?
Messages mFifo
container for FIFO items
Mutex mMutex
access serialization lock
virtual void onMessagePushed(int num)
virtual void setCountDepthTolerance(unsigned int max)
set the count depth tolerance of the FIFO
bool wouldAccept(DepthUsage usage) const
would an add called now work?
virtual size_t getCountDepth() const
gets the depth of the FIFO
Msg * getNext()
Returns the first message available.
virtual void setTimeDepthTolerance(unsigned int maxSecs)
set the time depth tolerance of the FIFO
virtual time_t getTimeDepth() const
Return the time depth of the queue.
TimeLimitFifo(unsigned int maxDurationSecs, unsigned int maxSize)
After it runs out of the lesser of these limits it will start to refuse messages.
Msg * getNext(int ms)
Returns the first message available within a time limit.
void clear()
removes all items from the FIFO
virtual size_t getCountDepthTolerance() const
returns the FIFO count depth tolerance
virtual time_t timeDepth() const
Return the time depth of the queue.
virtual time_t getTimeDepthTolerance() const
returns the FIFO time depth tolerance
bool add(Msg *msg, DepthUsage usage)
Add a message to the fifo.
wraps an object with a timestamp
const Payload & getMsg() const
void setMsg(const Payload &pMsg)
const time_t & getTime() const
Timestamped(const Payload &msg, time_t n)
dcm! – add UnusedChecking(_enum) below;
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...