From 7043d22d1943263840eb6cefdb7c6449eeab5a14 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 3 Apr 2007 21:18:17 +0000 Subject: Moved BasicMessage::WaitableDestination to IncomingMessage::WaitableDestination so it can be shared by Basic and Message implementations. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@525282 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/client/IncomingMessage.cpp | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'qpid/cpp/src/client/IncomingMessage.cpp') diff --git a/qpid/cpp/src/client/IncomingMessage.cpp b/qpid/cpp/src/client/IncomingMessage.cpp index 05c4bc2378..eb5f2b6fae 100644 --- a/qpid/cpp/src/client/IncomingMessage.cpp +++ b/qpid/cpp/src/client/IncomingMessage.cpp @@ -32,6 +32,44 @@ using sys::Mutex; IncomingMessage::Destination::~Destination() {} + +IncomingMessage::WaitableDestination::WaitableDestination() + : shutdownFlag(false) {} + +void IncomingMessage::WaitableDestination::message(const Message& msg) { + Mutex::ScopedLock l(monitor); + queue.push(msg); + monitor.notify(); +} + +void IncomingMessage::WaitableDestination::empty() { + Mutex::ScopedLock l(monitor); + queue.push(Empty()); + monitor.notify(); +} + +bool IncomingMessage::WaitableDestination::wait(Message& msgOut) { + Mutex::ScopedLock l(monitor); + while (queue.empty() && !shutdownFlag) + monitor.wait(); + if (shutdownFlag) + return false; + Message* msg = boost::get(&queue.front()); + bool success = msg; + if (success) + msgOut=*msg; + queue.pop(); + if (!queue.empty()) + monitor.notify(); // Wake another waiter. + return success; +} + +void IncomingMessage::WaitableDestination::shutdown() { + Mutex::ScopedLock l(monitor); + shutdownFlag = true; + monitor.notifyAll(); +} + void IncomingMessage::openReference(const std::string& name) { Mutex::ScopedLock l(lock); if (references.find(name) != references.end()) -- cgit v1.2.1