1
#if !defined(RESIP_FiniteFifo_hxx)
2
#define RESIP_FiniteFifo_hxx
4
#include "rutil/AbstractFifo.hxx"
6
// efficiency note: use a circular buffer do avoid list node allocation
8
// what happens to timers that can't be queued?
14
@brief A templated, threadsafe message-queue class with a fixed size.
15
@ingroup message_passing
19
template < class Msg >
20
class FiniteFifo : public AbstractFifo<Msg*>
23
FiniteFifo(unsigned int maxSize);
24
virtual ~FiniteFifo();
26
using AbstractFifo<Msg*>::mFifo;
27
using AbstractFifo<Msg*>::mMutex;
28
using AbstractFifo<Msg*>::mCondition;
29
using AbstractFifo<Msg*>::empty;
30
using AbstractFifo<Msg*>::size;
32
// Add a message to the fifo.
33
// return true if succeed, false if full
36
/** Returns the first message available. It will wait if no
37
* messages are available. If a signal interrupts the wait,
38
* it will retry the wait. Signals can therefore not be caught
39
* via getNext. If you need to detect a signal, use block
40
* prior to calling getNext.
44
/** Returns the next message available. Will wait up to
45
* ms milliseconds if no information is available. If
46
* the specified time passes or a signal interrupts the
47
* wait, this method returns 0. This interface provides
48
* no mechanism to distinguish between timeout and
53
unsigned int mMaxSize;
57
FiniteFifo<Msg>::FiniteFifo(unsigned int maxSize)
58
: AbstractFifo<Msg*>(),
64
FiniteFifo<Msg>::~FiniteFifo()
66
Lock lock(mMutex); (void)lock;
67
while ( ! mFifo.empty() )
76
FiniteFifo<Msg>::add(Msg* msg)
78
Lock lock(mMutex); (void)lock;
79
if (mFifo.size() >= mMaxSize)
93
FiniteFifo<Msg> ::getNext()
95
return AbstractFifo<Msg*>::getNext();
100
FiniteFifo<Msg> ::getNext(int ms)
103
AbstractFifo<Msg*>::getNext(ms, result);
111
/* ====================================================================
112
* The Vovida Software License, Version 1.0
114
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
116
* Redistribution and use in source and binary forms, with or without
117
* modification, are permitted provided that the following conditions
120
* 1. Redistributions of source code must retain the above copyright
121
* notice, this list of conditions and the following disclaimer.
123
* 2. Redistributions in binary form must reproduce the above copyright
124
* notice, this list of conditions and the following disclaimer in
125
* the documentation and/or other materials provided with the
128
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
129
* and "Vovida Open Communication Application Library (VOCAL)" must
130
* not be used to endorse or promote products derived from this
131
* software without prior written permission. For written
132
* permission, please contact vocal@vovida.org.
134
* 4. Products derived from this software may not be called "VOCAL", nor
135
* may "VOCAL" appear in their name, without prior written
136
* permission of Vovida Networks, Inc.
138
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
139
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
140
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
141
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
142
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
143
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
144
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
145
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
146
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
147
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
149
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
152
* ====================================================================
154
* This software consists of voluntary contributions made by Vovida
155
* Networks, Inc. and many individuals on behalf of Vovida Networks,
156
* Inc. For more information on Vovida Networks, Inc., please see
157
* <http://www.vovida.org/>.