From 081d94d64fa41df6f9661ad31afca0ad71fe9d12 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 2 Dec 2008 21:43:24 +0000 Subject: PollableQueue: fix unsafe use of deque git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@722622 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/PollableQueue.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid/sys/PollableQueue.h') diff --git a/cpp/src/qpid/sys/PollableQueue.h b/cpp/src/qpid/sys/PollableQueue.h index 2ee29db022..953d198fb0 100644 --- a/cpp/src/qpid/sys/PollableQueue.h +++ b/cpp/src/qpid/sys/PollableQueue.h @@ -121,14 +121,18 @@ template void PollableQueue::dispatch(sys::DispatchHandle& h) { assert(dispatcher.id() == 0 || dispatcher.id() == Thread::current().id()); dispatcher = Thread::current(); while (!stopped && !queue.empty()) { + T value = queue.front(); + queue.pop_front(); bool ok = false; { // unlock to allow concurrent push or call to stop() in callback. ScopedUnlock u(lock); - // FIXME aconway 2008-12-02: exception-safe if callback throws. - ok = callback(queue.front()); + // FIXME aconway 2008-12-02: not exception safe if callback throws. + ok = callback(value); + } + if (!ok) { // callback cannot process value, put it back. + queue.push_front(value); + stopped=true; } - if (ok) queue.pop_front(); - else stopped=true; } dispatcher = Thread(); if (queue.empty()) condition.clear(); -- cgit v1.2.1