31 #include <boost/format.hpp>
32 #include <boost/function.hpp>
33 #include <boost/noncopyable.hpp>
34 #include <boost/thread/condition.hpp>
35 #include <boost/thread/recursive_mutex.hpp>
38 #include "rsc/rscexports.h"
71 mutable boost::recursive_mutex
mutex;
106 boost::recursive_mutex::scoped_lock lock(
mutex);
134 M
pop(
const boost::uint32_t& timeoutMs = 0) {
136 boost::recursive_mutex::scoped_lock lock(
mutex);
139 if (timeoutMs == 0) {
142 #if BOOST_VERSION >= 105000
143 if (!
condition.timed_wait(lock, boost::posix_time::milliseconds(timeoutMs))) {
145 const boost::system_time timeout = boost::get_system_time()
146 + boost::posix_time::milliseconds(timeoutMs);
147 if (!
condition.timed_wait(lock, timeout)) {
149 throw QueueEmptyException(boost::str(boost::format(
"No element available on queue within %d ms.") % timeoutMs));
158 M message =
queue.front();
173 boost::recursive_mutex::scoped_lock lock(
mutex);
179 M message =
queue.front();
192 boost::recursive_mutex::scoped_lock lock(
mutex);
193 return queue.empty();
202 boost::recursive_mutex::scoped_lock lock(
mutex);
203 return this->
queue.size();
210 boost::recursive_mutex::scoped_lock lock(
mutex);
211 while (!this->
queue.empty()) {
223 boost::recursive_mutex::scoped_lock lock(
mutex);
SynchronizedQueue(const unsigned int &sizeLimit=0, dropHandlerType dropHandler=0)
Creates a new queue.
boost::condition condition
M pop(const boost::uint32_t &timeoutMs=0)
Returns the next element form the queue and wait until there is such an element.
virtual ~SynchronizedQueue()
boost::function< void(const M &drop)> dropHandlerType
bool empty() const
Checks whether this queue is empty.
An exception thrown if a blocking operation was interrupted.
M tryPop()
Tries to pop an element from the queue but does not wait if there is no element on the queue...
Indicates that a queue was empty while trying to pop an element from it.
boost::recursive_mutex mutex
void interrupt()
Interrupts the processing on this queue for every current call to pop and any later call...
void clear()
Remove all elements from the queue.
volatile bool interrupted
dropHandlerType dropHandler
std::size_t size() const
Return element count of the queue.
A queue with synchronized access and interruption support.
void push(const M &message)
Pushes a new element on the queue and wakes up one waiting client if there is one.