You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2009/01/12 20:57:35 UTC
svn commit: r733881 - /qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h
Author: gsim
Date: Mon Jan 12 11:57:30 2009
New Revision: 733881
URL: http://svn.apache.org/viewvc?rev=733881&view=rev
Log:
Allow any remaining events in PollableQueue to be processed after Poller threads return from poll loop.
Modified:
qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h?rev=733881&r1=733880&r2=733881&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/PollableQueue.h Mon Jan 12 11:57:30 2009
@@ -26,6 +26,7 @@
#include "qpid/sys/Dispatcher.h"
#include "qpid/sys/DispatchHandle.h"
#include "qpid/sys/Monitor.h"
+#include "qpid/sys/Thread.h"
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <algorithm>
@@ -71,12 +72,20 @@
size_t size() { ScopedLock l(lock); return queue.size(); }
bool empty() { ScopedLock l(lock); return queue.empty(); }
+
+ /**
+ * Allow any queued events to be processed; intended for calling
+ * after all dispatch threads exit the Poller loop in order to
+ * ensure clean shutdown with no events left on the queue.
+ */
+ void shutdown();
private:
typedef sys::Monitor::ScopedLock ScopedLock;
typedef sys::Monitor::ScopedUnlock ScopedUnlock;
void dispatch(sys::DispatchHandle&);
+ void process();
mutable sys::Monitor lock;
Callback callback;
@@ -119,6 +128,14 @@
ScopedLock l(lock);
assert(dispatcher.id() == 0);
dispatcher = Thread::current();
+ process();
+ dispatcher = Thread();
+ if (queue.empty()) condition.clear();
+ if (stopped) lock.notifyAll();
+ else h.rewatch();
+}
+
+template <class T> void PollableQueue<T>::process() {
while (!stopped && !queue.empty()) {
assert(batch.empty());
batch.swap(queue);
@@ -131,10 +148,11 @@
batch.clear();
}
}
- dispatcher = Thread();
- if (queue.empty()) condition.clear();
- if (stopped) lock.notifyAll();
- else h.rewatch();
+}
+
+template <class T> void PollableQueue<T>::shutdown() {
+ ScopedLock l(lock);
+ process();
}
template <class T> void PollableQueue<T>::stop() {