reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
FiniteFifo.hxx
Go to the documentation of this file.
1#if !defined(RESIP_FiniteFifo_hxx)
2#define RESIP_FiniteFifo_hxx
3
5
6// efficiency note: use a circular buffer do avoid list node allocation
7
8// what happens to timers that can't be queued?
9
10namespace resip
11{
12
19template < class Msg >
20class FiniteFifo : public AbstractFifo<Msg*>
21{
22 public:
23 FiniteFifo(unsigned int maxSize);
24 virtual ~FiniteFifo();
25
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;
31
32 // Add a message to the fifo.
33 // return true if succeed, false if full
34 bool add(Msg* msg);
35
42 Msg* getNext();
43
51 Msg* getNext(int ms);
52 private:
53 unsigned int mMaxSize;
54};
55
56template <class Msg>
57FiniteFifo<Msg>::FiniteFifo(unsigned int maxSize)
58 : AbstractFifo<Msg*>(),
59 mMaxSize(maxSize)
60{
61}
62
63template <class Msg>
65{
66 Lock lock(mMutex); (void)lock;
67 while ( ! mFifo.empty() )
68 {
69 delete mFifo.front();
70 mFifo.pop_front();
71 }
72}
73
74template <class Msg>
75bool
77{
78 Lock lock(mMutex); (void)lock;
79 if (mFifo.size() >= mMaxSize)
80 {
81 return false;
82 }
83 else
84 {
85 mFifo.push_back(msg);
86 mCondition.notify_one();
87 return true;
88 }
89}
90
91template <class Msg>
92Msg*
97
98template <class Msg>
99Msg*
101{
102 Msg* result(0);
103 AbstractFifo<Msg*>::getNext(ms, result);
104 return result;
105}
106
107} // namespace resip
108
109#endif
110
111/* ====================================================================
112 * The Vovida Software License, Version 1.0
113 *
114 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
115 *
116 * Redistribution and use in source and binary forms, with or without
117 * modification, are permitted provided that the following conditions
118 * are met:
119 *
120 * 1. Redistributions of source code must retain the above copyright
121 * notice, this list of conditions and the following disclaimer.
122 *
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
126 * distribution.
127 *
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.
133 *
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.
137 *
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
150 * DAMAGE.
151 *
152 * ====================================================================
153 *
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/>.
158 *
159 */
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
T getNext()
Returns the first message available.
bool empty() const
is the queue empty?
Messages mFifo
container for FIFO items
Mutex mMutex
access serialization lock
A templated, threadsafe message-queue class with a fixed size.
bool add(Msg *msg)
FiniteFifo(unsigned int maxSize)
Msg * getNext()
Returns the first message available.
virtual ~FiniteFifo()
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...
Definition Lock.hxx:28