diff options
| author | Alan Conway <aconway@apache.org> | 2008-12-02 21:43:24 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-12-02 21:43:24 +0000 |
| commit | 081d94d64fa41df6f9661ad31afca0ad71fe9d12 (patch) | |
| tree | 6a4fe30676916a45a8ab2f24a62f768c0e4162c4 /cpp/src/qpid/sys/PollableQueue.h | |
| parent | 7cdb9a9ab688988e596d9fce116a0998decd0972 (diff) | |
| download | qpid-python-081d94d64fa41df6f9661ad31afca0ad71fe9d12.tar.gz | |
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
Diffstat (limited to 'cpp/src/qpid/sys/PollableQueue.h')
| -rw-r--r-- | cpp/src/qpid/sys/PollableQueue.h | 12 |
1 files changed, 8 insertions, 4 deletions
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 <class T> void PollableQueue<T>::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(); |
