From 557cfbb842f88800d31d84a9109f4398e9a645d7 Mon Sep 17 00:00:00 2001 From: Jonathan Marsden Date: Wed, 2 Aug 2017 11:47:41 -0700 Subject: [PATCH 1/2] See if the dispatch queue length has been updated on Cancel --- src/autowiring/test/DispatchQueueTest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/autowiring/test/DispatchQueueTest.cpp b/src/autowiring/test/DispatchQueueTest.cpp index 8a7982f51..198b27b18 100644 --- a/src/autowiring/test/DispatchQueueTest.cpp +++ b/src/autowiring/test/DispatchQueueTest.cpp @@ -291,7 +291,9 @@ TEST_F(DispatchQueueTest, SimpleCancel) { DispatchQueue dq; auto called = std::make_shared(false); dq += [called] { *called = true; }; + ASSERT_EQ(1U, dq.GetDispatchQueueLength()); ASSERT_TRUE(dq.Cancel()) << "Dispatch queue failed to cancel a lambda as expected"; + ASSERT_EQ(0U, dq.GetDispatchQueueLength()); ASSERT_FALSE(dq.DispatchEvent()) << "Succeeded in dispatching an event that should not have been dispatched"; ASSERT_FALSE(*called) << "Dispatch queue executed a lambda that should have been destroyed"; ASSERT_TRUE(called.unique()) << "Dispatch queue leaked a lambda function"; From c50f5158ddb6acb27e8cb45bf4b89759a0480cf2 Mon Sep 17 00:00:00 2001 From: Jonathan Marsden Date: Wed, 2 Aug 2017 11:49:39 -0700 Subject: [PATCH 2/2] Properly decrement the dispatch queue count on Cancel --- src/autowiring/DispatchQueue.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/autowiring/DispatchQueue.cpp b/src/autowiring/DispatchQueue.cpp index 3e5096fac..62397793b 100644 --- a/src/autowiring/DispatchQueue.cpp +++ b/src/autowiring/DispatchQueue.cpp @@ -163,6 +163,7 @@ bool DispatchQueue::Cancel(void) { // Found a ready thunk, run from here: thunk.reset(m_pHead); m_pHead = thunk->m_pFlink; + m_count--; } else if (!m_delayedQueue.empty()) { auto& f = m_delayedQueue.top();