From ed5f5cceb580b70c8f87e1d630db4e76411334cb Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Mon, 26 Nov 2012 22:02:07 +0000 Subject: Prevent multiple threads from dispatching the condition handling at once. Fixes QPID-4424. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1413889 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/sys/windows/PollableCondition.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'qpid/cpp/src') diff --git a/qpid/cpp/src/qpid/sys/windows/PollableCondition.cpp b/qpid/cpp/src/qpid/sys/windows/PollableCondition.cpp index 7bbcd4de1b..3e2a5fb36c 100644 --- a/qpid/cpp/src/qpid/sys/windows/PollableCondition.cpp +++ b/qpid/cpp/src/qpid/sys/windows/PollableCondition.cpp @@ -52,13 +52,14 @@ private: PollableCondition& parent; boost::shared_ptr poller; LONG isSet; + LONG isDispatching; }; PollableConditionPrivate::PollableConditionPrivate(const sys::PollableCondition::Callback& cb, sys::PollableCondition& parent, const boost::shared_ptr& poller) : IOHandle(INVALID_SOCKET, boost::bind(&PollableConditionPrivate::dispatch, this, _1)), - cb(cb), parent(parent), poller(poller), isSet(0) + cb(cb), parent(parent), poller(poller), isSet(0), isDispatching(0) { } @@ -77,7 +78,12 @@ void PollableConditionPrivate::poke() void PollableConditionPrivate::dispatch(windows::AsynchIoResult *result) { delete result; // Poller::monitorHandle() allocates this + // If isDispatching is already set, just return. Else, enter. + if (::InterlockedCompareExchange(&isDispatching, 1, 0) == 1) + return; cb(parent); + LONG oops = ::InterlockedDecrement(&isDispatching); // Result must be 0 + assert(!oops); if (isSet) poke(); } -- cgit v1.2.1