8
#include "rutil/Condition.hxx"
9
#include "rutil/Mutex.hxx"
10
#include "rutil/Lock.hxx"
11
#include "rutil/AbstractFifo.hxx"
12
#include "resip/stack/CancelableTimerQueue.hxx"
20
Distinct from resip::Fifo; by value and has cancellable timers.
23
class ValueFifo : public resip::FifoStatsInterface
26
typedef typename CancelableTimerQueue<T>::Id TimerId;
28
ValueFifo(const Data& name) :
40
resip::Lock lock(myMutex);
46
TimerId addDelayMs(const T& t, int offsetInMs)
48
resip::Lock lock(myMutex);
54
bool doWakeup = false;
55
if (myTimerQueue.empty() ||
56
offsetInMs < myTimerQueue.getTimeout())
61
TimerId id = myTimerQueue.addRelative(t, offsetInMs);
64
//wakeup if new timer is sooner than next timer that would have
65
//fired, or no timer set
74
bool cancel(TimerId id)
76
resip::Lock lock(myMutex);
77
if (myTimerQueue.cancel(id))
87
resip::Lock lock(myMutex);
89
while (!messageAvailableNoLock())
91
if (myTimerQueue.empty())
93
myCondition.wait(&myMutex);
97
myCondition.wait(&myMutex, myTimerQueue.getTimeout());
101
while (myTimerQueue.available())
103
myList.push_back(myTimerQueue.getNext());
108
assert (myFifoSize > 0);
109
assert (!myList.empty());
111
T firstMessage = myList.front();
113
myList.pop_front(); //dcm -- should do this with a guard to avoid extra copy
120
resip::Lock lock(myMutex);
123
myTimerQueue.clear();
127
//size includes timer events
128
unsigned int size() const
130
resip::Lock lock(myMutex);
131
return myFifoSize + myTimerSize;
136
return myFifoSize + myTimerSize == 0;
139
bool messageAvailable()
141
resip::Lock lock(myMutex);
142
return messageAvailableNoLock();
145
virtual size_t getCountDepth() const
150
virtual time_t getTimeDepth() const
155
virtual time_t expectedWaitTimeMilliSec() const
160
virtual time_t averageServiceTimeMicroSec() const
166
bool messageAvailableNoLock()
168
return myFifoSize > 0 || myTimerQueue.available();
173
myCondition.signal();
176
std::deque<T> myList;
178
CancelableTimerQueue<T> myTimerQueue;
180
unsigned long myFifoSize;
181
unsigned long myTimerSize;
183
mutable resip::Mutex myMutex;
184
resip::Condition myCondition;
186
// no value semantics
187
ValueFifo(const ValueFifo&);
188
ValueFifo& operator=(const ValueFifo&);
194
/* ====================================================================
195
* The Vovida Software License, Version 1.0
197
* Copyright (c) 2004 PurpleComm, Inc. All rights reserved.
199
* Redistribution and use in source and binary forms, with or without
200
* modification, are permitted provided that the following conditions
203
* 1. Redistributions of source code must retain the above copyright
204
* notice, this list of conditions and the following disclaimer.
206
* 2. Redistributions in binary form must reproduce the above copyright
207
* notice, this list of conditions and the following disclaimer in
208
* the documentation and/or other materials provided with the
211
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
212
* and "Vovida Open Communication Application Library (VOCAL)" must
213
* not be used to endorse or promote products derived from this
214
* software without prior written permission. For written
215
* permission, please contact vocal@vovida.org.
217
* 4. Products derived from this software may not be called "VOCAL", nor
218
* may "VOCAL" appear in their name, without prior written
219
* permission of Vovida Networks, Inc.
221
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
222
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
224
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
225
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
226
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
227
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
228
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
229
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
230
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
232
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH