diff options
author | Alan Conway <aconway@apache.org> | 2007-10-29 21:14:44 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-10-29 21:14:44 +0000 |
commit | da6e2b9f62966ef7d0cb69f58ffe1365af98d676 (patch) | |
tree | a46b84d820f2c26f6094f092e18a0937deb46ecf /cpp/src | |
parent | 505c43651b302ecf773bff1fcf3d45f5a1aef682 (diff) | |
download | qpid-python-da6e2b9f62966ef7d0cb69f58ffe1365af98d676.tar.gz |
client/BlockingQueue.h, sys/ConcurrentQueue.h: merged to sys/BlockingQueue.h
- updated all users
qpid/Exception.h: Removed unimplemented clone() function.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@589857 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Makefile.am | 3 | ||||
-rw-r--r-- | cpp/src/qpid/Exception.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/Exception.h | 9 | ||||
-rw-r--r-- | cpp/src/qpid/client/BlockingQueue.h | 93 | ||||
-rw-r--r-- | cpp/src/qpid/client/Channel.cpp | 11 | ||||
-rw-r--r-- | cpp/src/qpid/client/Channel.h | 2 | ||||
-rw-r--r-- | cpp/src/qpid/client/Demux.h | 4 | ||||
-rw-r--r-- | cpp/src/qpid/client/Dispatcher.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/client/MessageQueue.h | 33 | ||||
-rw-r--r-- | cpp/src/qpid/client/SessionCore.cpp | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/BlockingQueue.h | 127 | ||||
-rw-r--r-- | cpp/src/qpid/sys/ConcurrentQueue.h | 111 | ||||
-rw-r--r-- | cpp/src/qpid/sys/Waitable.h | 28 | ||||
-rw-r--r-- | cpp/src/tests/Cluster.cpp | 8 | ||||
-rw-r--r-- | cpp/src/tests/Cluster.h | 6 | ||||
-rw-r--r-- | cpp/src/tests/Cluster_child.cpp | 3 | ||||
-rw-r--r-- | cpp/src/tests/ConcurrentQueue.cpp | 6 | ||||
-rw-r--r-- | cpp/src/tests/InProcessBroker.h | 29 |
18 files changed, 195 insertions, 288 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index ebb8916d6a..b6337f615c 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -294,7 +294,6 @@ nobase_include_HEADERS = \ qpid/broker/TxOp.h \ qpid/broker/TxPublish.h \ qpid/client/AckMode.h \ - qpid/client/BlockingQueue.h \ qpid/client/ChainableFrameHandler.h \ qpid/client/Channel.h \ qpid/client/Exchange.h \ @@ -378,7 +377,7 @@ nobase_include_HEADERS = \ qpid/sys/Acceptor.h \ qpid/sys/AsynchIO.h \ qpid/sys/AtomicCount.h \ - qpid/sys/ConcurrentQueue.h \ + qpid/sys/BlockingQueue.h \ qpid/sys/Condition.h \ qpid/sys/ConnectionInputHandler.h \ qpid/sys/ConnectionInputHandlerFactory.h \ diff --git a/cpp/src/qpid/Exception.cpp b/cpp/src/qpid/Exception.cpp index e0747df49e..b25a6dc8f8 100644 --- a/cpp/src/qpid/Exception.cpp +++ b/cpp/src/qpid/Exception.cpp @@ -46,8 +46,4 @@ std::string Exception::str() const throw() { const char* Exception::what() const throw() { return str().c_str(); } -std::auto_ptr<Exception> Exception::clone() const throw() { - return std::auto_ptr<Exception>(new Exception(*this)); -} - } // namespace qpid diff --git a/cpp/src/qpid/Exception.h b/cpp/src/qpid/Exception.h index bf6c1fb872..4ca15b37fc 100644 --- a/cpp/src/qpid/Exception.h +++ b/cpp/src/qpid/Exception.h @@ -44,7 +44,6 @@ class Exception : public std::exception virtual ~Exception() throw(); virtual const char *what() const throw(); - virtual std::auto_ptr<Exception> clone() const throw(); virtual std::string str() const throw(); private: std::string msg; @@ -62,14 +61,6 @@ struct ConnectionException : public Exception { : Exception(message), code(code_) {} }; -/** Clone an exception. - * For qpid::Exception this calls the clone member function. - * For standard exceptions, uses the copy constructor. - * For unknown exception types creates a std::exception - * with the same what() string. - */ -std::auto_ptr<std::exception> clone(const std::exception&); - } // namespace qpid #endif /*!_Exception_*/ diff --git a/cpp/src/qpid/client/BlockingQueue.h b/cpp/src/qpid/client/BlockingQueue.h deleted file mode 100644 index 3ec7dbcf44..0000000000 --- a/cpp/src/qpid/client/BlockingQueue.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#ifndef _BlockingQueue_ -#define _BlockingQueue_ - -#include <queue> -#include "qpid/sys/Monitor.h" - -namespace qpid { -namespace client { - -struct QueueClosed {}; - -template <class T> -class BlockingQueue -{ - sys::Monitor lock; - std::queue<T> queue; - bool closed; - -public: - - BlockingQueue() : closed(false) {} - - void reset() - { - sys::Monitor::ScopedLock l(lock); - closed = true; - } - - T pop() - { - sys::Monitor::ScopedLock l(lock); - while (!closed && queue.empty()) { - lock.wait(); - } - if (closed) { - throw QueueClosed(); - } else { - T t = queue.front(); - queue.pop(); - return t; - } - } - - void push(const T& t) - { - sys::Monitor::ScopedLock l(lock); - bool wasEmpty = queue.empty(); - queue.push(t); - if (wasEmpty) { - lock.notifyAll(); - } - } - - void close() - { - sys::Monitor::ScopedLock l(lock); - closed = true; - lock.notifyAll(); - } - - bool empty() - { - sys::Monitor::ScopedLock l(lock); - return queue.empty(); - } -}; - -}} - - - -#endif diff --git a/cpp/src/qpid/client/Channel.cpp b/cpp/src/qpid/client/Channel.cpp index 8b7b7e1118..fbb2e0c6f8 100644 --- a/cpp/src/qpid/client/Channel.cpp +++ b/cpp/src/qpid/client/Channel.cpp @@ -187,13 +187,14 @@ bool Channel::get(Message& msg, const Queue& _queue, AckMode ackMode) { status.sync(); session.messageCancel(tag); - if (incoming.empty()) { - return false; - } else { - msg.populate(*(incoming.pop())); + FrameSet::shared_ptr p; + if (incoming.tryPop(p)) { + msg.populate(*p); if (ackMode == AUTO_ACK) msg.acknowledge(session, false, true); return true; } + else + return false; } void Channel::publish(Message& msg, const Exchange& exchange, @@ -263,7 +264,7 @@ void Channel::run() { QPID_LOG(warning, "Dropping unsupported message type: " << content->getMethod()); } } - } catch (const QueueClosed&) {} + } catch (const sys::QueueClosed&) {} } }} diff --git a/cpp/src/qpid/client/Channel.h b/cpp/src/qpid/client/Channel.h index 19a3a2de8c..c1f74e0706 100644 --- a/cpp/src/qpid/client/Channel.h +++ b/cpp/src/qpid/client/Channel.h @@ -80,7 +80,7 @@ class Channel : private sys::Runnable ConsumerMap consumers; Session_0_10 session; framing::ChannelId channelId; - BlockingQueue<framing::FrameSet::shared_ptr> gets; + sys::BlockingQueue<framing::FrameSet::shared_ptr> gets; framing::Uuid uniqueId; uint32_t nameCounter; bool active; diff --git a/cpp/src/qpid/client/Demux.h b/cpp/src/qpid/client/Demux.h index 0f261f70ba..3c9d4a4857 100644 --- a/cpp/src/qpid/client/Demux.h +++ b/cpp/src/qpid/client/Demux.h @@ -24,7 +24,7 @@ #include <boost/shared_ptr.hpp> #include "qpid/framing/FrameSet.h" #include "qpid/sys/Mutex.h" -#include "BlockingQueue.h" +#include "qpid/sys/BlockingQueue.h" #ifndef _Demux_ #define _Demux_ @@ -44,7 +44,7 @@ class Demux { public: typedef boost::function<bool(const framing::FrameSet&)> Condition; - typedef BlockingQueue<framing::FrameSet::shared_ptr> Queue; + typedef sys::BlockingQueue<framing::FrameSet::shared_ptr> Queue; void handle(framing::FrameSet::shared_ptr); void close(); diff --git a/cpp/src/qpid/client/Dispatcher.cpp b/cpp/src/qpid/client/Dispatcher.cpp index ea6fcfb463..37f3941022 100644 --- a/cpp/src/qpid/client/Dispatcher.cpp +++ b/cpp/src/qpid/client/Dispatcher.cpp @@ -24,7 +24,7 @@ #include "qpid/framing/FrameSet.h" #include "qpid/framing/MessageTransferBody.h" #include "qpid/log/Statement.h" -#include "BlockingQueue.h" +#include "qpid/sys/BlockingQueue.h" #include "Message.h" using qpid::framing::FrameSet; @@ -62,7 +62,7 @@ void Dispatcher::start() void Dispatcher::run() { - BlockingQueue<FrameSet::shared_ptr>& q = queue.empty() ? + sys::BlockingQueue<FrameSet::shared_ptr>& q = queue.empty() ? session.execution().getDemux().getDefault() : session.execution().getDemux().get(queue); diff --git a/cpp/src/qpid/client/MessageQueue.h b/cpp/src/qpid/client/MessageQueue.h index 1f5c492910..8ff537701f 100644 --- a/cpp/src/qpid/client/MessageQueue.h +++ b/cpp/src/qpid/client/MessageQueue.h @@ -22,28 +22,29 @@ #ifndef _MessageQueue_ #define _MessageQueue_ #include <iostream> -#include "BlockingQueue.h" +#include "qpid/sys/BlockingQueue.h" #include "MessageListener.h" namespace qpid { namespace client { - /** - * A MessageListener implementation that simply queues up - * messages. - * - * \ingroup clientapi - */ - class MessageQueue : public MessageListener, public BlockingQueue<Message> +/** + * A MessageListener implementation that simply queues up + * messages. + * + * \ingroup clientapi + */ +class MessageQueue : public MessageListener, + public sys::BlockingQueue<Message> +{ + std::queue<Message> messages; + public: + void received(Message& msg) { - std::queue<Message> messages; - public: - void received(Message& msg) - { - std::cout << "Adding message to queue: " << msg.getData() << std::endl; - push(msg); - } - }; + std::cout << "Adding message to queue: " << msg.getData() << std::endl; + push(msg); + } +}; } } diff --git a/cpp/src/qpid/client/SessionCore.cpp b/cpp/src/qpid/client/SessionCore.cpp index 27440465fe..ea877f9b40 100644 --- a/cpp/src/qpid/client/SessionCore.cpp +++ b/cpp/src/qpid/client/SessionCore.cpp @@ -120,7 +120,7 @@ SessionCore::~SessionCore() { Lock l(state); invariant(); detach(COMMAND_INVALID, "Session deleted"); - state.waitAll(); + state.waitWaiters(); } void SessionCore::detach(int c, const std::string& t) { diff --git a/cpp/src/qpid/sys/BlockingQueue.h b/cpp/src/qpid/sys/BlockingQueue.h new file mode 100644 index 0000000000..65196dbd9c --- /dev/null +++ b/cpp/src/qpid/sys/BlockingQueue.h @@ -0,0 +1,127 @@ +#ifndef QPID_SYS_BLOCKINGQUEUE_H +#define QPID_SYS_BLOCKINGQUEUE_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "Waitable.h" + +#include <queue> + +namespace qpid { +namespace sys { + +struct QueueClosed {}; + +template <class T> +class BlockingQueue +{ + sys::Waitable lock; + std::queue<T> queue; + bool closed; + +public: + BlockingQueue() : closed(false) {} + ~BlockingQueue() { close(); } + + /** Block until there is a value to pop */ + T pop() + { + Waitable::ScopedLock l(lock); + if (!queueWait()) throw QueueClosed(); + return popInternal(); + } + + /** Non-blocking pop. If there is a value set outValue and return + * true, else return false; + */ + bool tryPop(T& outValue) { + Waitable::ScopedLock l(lock); + if (queue.empty()) return false; + outValue = popInternal(); + return true; + } + + /** Non-blocking pop. If there is a value return it, else return + * valueIfEmpty. + */ + T tryPop(const T& valueIfEmpty=T()) { + T result=valueIfEmpty; + tryPop(result); + return result; + } + + /** Push a value onto the queue */ + void push(const T& t) + { + Waitable::ScopedLock l(lock); + queue.push(t); + queueNotify(0); + } + + /** + * Close the queue. Throws QueueClosed in threads waiting in pop(). + * Blocks till all waiting threads have been notified. + */ + void close() + { + Waitable::ScopedLock l(lock); + if (!closed) { + closed = true; + lock.notifyAll(); + lock.waitWaiters(); // Ensure no threads are still waiting. + } + } + + /** Open a closed queue. */ + void open() { + Waitable::ScopedLock l(lock); + closed=false; + } + + private: + + void queueNotify(size_t ignore) { + if (!queue.empty() && lock.hasWaiters()>ignore) + lock.notify(); // Notify another waiter. + } + + bool queueWait() { + Waitable::ScopedWait w(lock); + while (!closed && queue.empty()) + lock.wait(); + return !queue.empty(); + } + + T popInternal() { + T t=queue.front(); + queue.pop(); + queueNotify(1); + return t; + } + +}; + +}} + + + +#endif /*!QPID_SYS_BLOCKINGQUEUE_H*/ diff --git a/cpp/src/qpid/sys/ConcurrentQueue.h b/cpp/src/qpid/sys/ConcurrentQueue.h deleted file mode 100644 index 43e82cadce..0000000000 --- a/cpp/src/qpid/sys/ConcurrentQueue.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef QPID_SYS_CONCURRENTQUEUE_H -#define QPID_SYS_CONCURRENTQUEUE_H - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "qpid/sys/Waitable.h" -#include "qpid/sys/ScopedIncrement.h" - -#include <boost/bind.hpp> - -#include <deque> - -namespace qpid { -namespace sys { - -/** - * Thread-safe queue that allows threads to push items onto - * the queue concurrently with threads popping items off the - * queue. - * - * Also allows consuming threads to wait until an item is available. - */ -template <class T> class ConcurrentQueue : public Waitable { - public: - struct ShutdownException {}; - - ConcurrentQueue() : shutdownFlag(false) {} - - /** Waiting threads are notified by ~Waitable */ - ~ConcurrentQueue() { shutdown(); } - - bool shutdown(bool wait=true) { - ScopedLock l(lock); - if (!shutdownFlag) { - shutdownFlag=true; - lock.notifyAll(); - if (wait) lock.waitAll(); - shutdownFlag=true; - return true; - } - return false; - } - - /** Push a data item onto the back of the queue */ - void push(const T& data) { - Mutex::ScopedLock l(lock); - queue.push_back(data); - lock.notify(); - } - - /** If the queue is non-empty, pop the front item into data and - * return true. If the queue is empty, return false - */ - bool tryPop(T& data) { - Mutex::ScopedLock l(lock); - if (shutdownFlag || queue.empty()) - return false; - data = queue.front(); - queue.pop_front(); - return true; - } - - /** Wait for a data item to be available. - * Return false if shut down. - */ - bool waitPop(T& data) { - ScopedLock l(lock); - { - ScopedWait(*this); - while (!shutdownFlag && queue.empty()) - lock.wait(); - } - if (queue.empty()) - return false; - data = queue.front(); - queue.pop_front(); - return true; - } - - bool isShutdown() { ScopedLock l(lock); return shutdownFlag; } - - protected: - Waitable lock; - private: - std::deque<T> queue; - bool shutdownFlag; -}; - -}} // namespace qpid::sys - - -#endif /*!QPID_SYS_CONCURRENTQUEUE_H*/ diff --git a/cpp/src/qpid/sys/Waitable.h b/cpp/src/qpid/sys/Waitable.h index eb71a1d742..37392ed761 100644 --- a/cpp/src/qpid/sys/Waitable.h +++ b/cpp/src/qpid/sys/Waitable.h @@ -29,9 +29,9 @@ namespace qpid { namespace sys { /** - * A monitor that keeps track of waiting threads. - * Threads that use a WaitLock are counted as waiters, threads that - * use a normal ScopedLock are not considered waiters. + * A monitor that keeps track of waiting threads. Threads declare a + * ScopedWait around wait() inside a ScopedLock to be considered + * waiters. */ class Waitable : public Monitor { public: @@ -43,24 +43,22 @@ class Waitable : public Monitor { struct ScopedWait { Waitable& w; ScopedWait(Waitable& w_) : w(w_) { ++w.waiters; } - ~ScopedWait() { --w.waiters; w.notifyAll(); } + ~ScopedWait() { if (--w.waiters==0) w.notifyAll(); } }; - /** Block till all waiters have finished waiting. - * The calling thread does not count as a waiter. + /** Block till there are no more ScopedWaits. *@pre Must be called inside a ScopedLock but NOT a ScopedWait. */ - bool waitAll(Duration timeout=TIME_INFINITE) { - AbsTime deadline(now(), timeout); - while (waiters > 0) { - if (!wait(deadline)) { - assert(timeout != TIME_INFINITE); - return false; - } - } - return true; + void waitWaiters() { + while (waiters != 0) + wait(); } + /** Returns the number of outstanding ScopedWaits. + * Must be called with the lock held. + */ + size_t hasWaiters() { return waiters; } + private: friend struct ScopedWait; size_t waiters; diff --git a/cpp/src/tests/Cluster.cpp b/cpp/src/tests/Cluster.cpp index 531a74b0c2..ee13bdd72a 100644 --- a/cpp/src/tests/Cluster.cpp +++ b/cpp/src/tests/Cluster.cpp @@ -36,8 +36,7 @@ BOOST_AUTO_TEST_CASE(testClusterOne) { TestCluster cluster("clusterOne", "amqp:one:1"); AMQFrame send(1, SessionOpenBody(VER)); cluster.handle(send); - AMQFrame received; - BOOST_REQUIRE(cluster.received.waitPop(received)); + AMQFrame received = cluster.received.pop(); BOOST_CHECK_TYPEID_EQUAL(SessionOpenBody, *received.getBody()); BOOST_CHECK_EQUAL(1u, cluster.size()); Cluster::MemberList members = cluster.getMembers(); @@ -62,11 +61,10 @@ BOOST_AUTO_TEST_CASE(testClusterTwo) { // Exchange frames with child. AMQFrame send(1, SessionOpenBody(VER)); cluster.handle(send); - AMQFrame received; - BOOST_REQUIRE(cluster.received.waitPop(received)); + AMQFrame received = cluster.received.pop(); BOOST_CHECK_TYPEID_EQUAL(SessionOpenBody, *received.getBody()); - BOOST_REQUIRE(cluster.received.waitPop(received)); + received=cluster.received.pop(); BOOST_CHECK_TYPEID_EQUAL(SessionAttachedBody, *received.getBody()); if (!nofork) { diff --git a/cpp/src/tests/Cluster.h b/cpp/src/tests/Cluster.h index d14d7c1392..6ff5c21fdb 100644 --- a/cpp/src/tests/Cluster.h +++ b/cpp/src/tests/Cluster.h @@ -20,7 +20,7 @@ */ #include "qpid/cluster/Cluster.h" -#include "qpid/sys/ConcurrentQueue.h" +#include "qpid/sys/BlockingQueue.h" #include "qpid/framing/AMQFrame.h" #include <boost/bind.hpp> @@ -45,12 +45,10 @@ using namespace boost; void null_deleter(void*) {} template <class T> -class TestHandler : public Handler<T&>, public ConcurrentQueue<T> +class TestHandler : public Handler<T&>, public BlockingQueue<T> { public: void handle(T& frame) { push(frame); } - bool waitPop(T& x) { return waitPop(x, TIME_SEC); } - using ConcurrentQueue<T>::waitPop; }; typedef TestHandler<AMQFrame> TestFrameHandler; diff --git a/cpp/src/tests/Cluster_child.cpp b/cpp/src/tests/Cluster_child.cpp index c03d7396f0..8d0682473b 100644 --- a/cpp/src/tests/Cluster_child.cpp +++ b/cpp/src/tests/Cluster_child.cpp @@ -35,8 +35,7 @@ static const ProtocolVersion VER; /** Child part of Cluster::clusterTwo test */ void clusterTwo() { TestCluster cluster("clusterTwo", "amqp:child:2"); - AMQFrame frame; - BOOST_REQUIRE(cluster.received.waitPop(frame)); // Frame from parent. + AMQFrame frame = cluster.received.pop(frame); // Frame from parent. BOOST_CHECK_TYPEID_EQUAL(SessionOpenBody, *frame.getBody()); BOOST_CHECK_EQUAL(2u, cluster.size()); // Me and parent diff --git a/cpp/src/tests/ConcurrentQueue.cpp b/cpp/src/tests/ConcurrentQueue.cpp index 39155b4ff2..c6ca40e897 100644 --- a/cpp/src/tests/ConcurrentQueue.cpp +++ b/cpp/src/tests/ConcurrentQueue.cpp @@ -20,10 +20,10 @@ */ /**@file - * Compare alternative implementations for ConcurrentQueue. + * Compare alternative implementations for BlockingQueue. */ -#include "qpid/sys/ConcurrentQueue.h" +#include "qpid/sys/BlockingQueue.h" #include "qpid/sys/Thread.h" #include "qpid/sys/Monitor.h" #include "qpid/sys/Runnable.h" @@ -83,7 +83,7 @@ template <class T> class DualVectorDualLockQueue { typename std::vector<T>::iterator popIter; }; -template <class T> struct LockedDequeQueue : public ConcurrentQueue<T> { +template <class T> struct LockedDequeQueue : public BlockingQueue<T> { /** size_t ignored, can't pre-allocate space in a dequeue */ LockedDequeQueue(size_t=0) {}; }; diff --git a/cpp/src/tests/InProcessBroker.h b/cpp/src/tests/InProcessBroker.h index c5860568db..3f6ff0936e 100644 --- a/cpp/src/tests/InProcessBroker.h +++ b/cpp/src/tests/InProcessBroker.h @@ -26,7 +26,7 @@ #include "qpid/client/Connection.h" #include "qpid/log/Statement.h" #include "qpid/sys/Thread.h" -#include "qpid/sys/ConcurrentQueue.h" +#include "qpid/sys/BlockingQueue.h" #include "qpid/shared_ptr.h" #include <vector> @@ -65,26 +65,29 @@ class InProcessConnector : } ~NetworkQueue() { - queue.shutdown(); + queue.close(); thread.join(); } void push(AMQFrame& f) { queue.push(f); } void run() { - AMQFrame f; - while (queue.waitPop(f)) { - Lock l(lock); - if (inputHandler) { - QPID_LOG(debug, QPID_MSG(receiver << " RECV: " << f)); - inputHandler->handle(f); - } - else { - QPID_LOG(debug, QPID_MSG(receiver << " DROP: " << f)); + try { + while(true) { + AMQFrame f = queue.pop(); + if (inputHandler) { + QPID_LOG(debug, QPID_MSG(receiver << " RECV: " << f)); + inputHandler->handle(f); + } + else + QPID_LOG(debug, QPID_MSG(receiver << " DROP: " << f)); } } + catch (const sys::QueueClosed&) { + return; + } } - + void setInputHandler(FrameHandler* h) { Lock l(lock); inputHandler = h; @@ -92,7 +95,7 @@ class InProcessConnector : private: sys::Mutex lock; - sys::ConcurrentQueue<AMQFrame> queue; + sys::BlockingQueue<AMQFrame> queue; sys::Thread thread; FrameHandler* inputHandler; const char* const receiver; |