Skip to content

Commit

Permalink
Merge pull request #1023 from leapmotion/fix-dq-cancel
Browse files Browse the repository at this point in the history
Fix DispatchQueue length on Cancel
  • Loading branch information
jdonald authored Aug 2, 2017
2 parents 62cc3ff + c50f515 commit 5f4a12a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/autowiring/DispatchQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/autowiring/test/DispatchQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ TEST_F(DispatchQueueTest, SimpleCancel) {
DispatchQueue dq;
auto called = std::make_shared<bool>(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";
Expand Down

0 comments on commit 5f4a12a

Please sign in to comment.