[Win] WTF::WorkQueue does not balance ref/deref properly
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2015 04:15:42 +0000 (04:15 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2015 04:15:42 +0000 (04:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142471

Reviewed by Antti Koivisto.

Source/WTF:

Make sure we deref the count when we execute a function in the
WorkQueue.

* wtf/win/WorkQueueWin.cpp:
(WTF::WorkQueue::performWorkOnRegisteredWorkThread):

Tools:

* TestWebKitAPI/Tests/WTF/WorkQueue.cpp:
(TestWebKitAPI::TEST): Check that the refcount is correct.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181257 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/win/WorkQueueWin.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/WorkQueue.cpp

index 2e9381d..8cf01d0 100644 (file)
@@ -1,3 +1,16 @@
+2015-03-08  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] WTF::WorkQueue does not balance ref/deref properly
+        https://bugs.webkit.org/show_bug.cgi?id=142471
+
+        Reviewed by Antti Koivisto.
+
+        Make sure we deref the count when we execute a function in the
+        WorkQueue.
+
+        * wtf/win/WorkQueueWin.cpp:
+        (WTF::WorkQueue::performWorkOnRegisteredWorkThread):
+
 2015-03-07  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Revive WTF::WorkQueue on Windows
index 310fcfd..aee15fd 100644 (file)
@@ -82,8 +82,10 @@ void WorkQueue::performWorkOnRegisteredWorkThread()
 
         // Allow more work to be scheduled while we're not using the queue directly.
         m_workItemQueueLock.unlock();
-        for (auto& workItem : workItemQueue)
+        for (auto& workItem : workItemQueue) {
             workItem->function()();
+            deref();
+        }
         m_workItemQueueLock.lock();
     }
 
index dce894a..892952c 100644 (file)
@@ -1,3 +1,13 @@
+2015-03-08  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] WTF::WorkQueue does not balance ref/deref properly
+        https://bugs.webkit.org/show_bug.cgi?id=142471
+
+        Reviewed by Antti Koivisto.
+
+        * TestWebKitAPI/Tests/WTF/WorkQueue.cpp:
+        (TestWebKitAPI::TEST): Check that the refcount is correct.
+
 2015-03-08  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Do not show passing test result on output of EFL layout test
index 32e6aa2..f9cc8a7 100644 (file)
@@ -53,13 +53,15 @@ TEST(WTF_WorkQueue, Simple)
     static const char* thirdTestLabel = "thirdTest";
 
     auto queue = WorkQueue::create("com.apple.WebKit.Test.simple");
-    
+    int initialRefCount = queue->refCount();
+    EXPECT_EQ(1, initialRefCount);
+
     MutexLocker locker(m_lock);
     queue->dispatch([&](void) {
         m_functionCallOrder.append(simpleTestLabel);
         calledSimpleTest = true;
     });
-    
+
     queue->dispatch([&](void) {
         m_functionCallOrder.append(longTestLabel);
         std::this_thread::sleep_for(std::chrono::nanoseconds(100));
@@ -78,13 +80,17 @@ TEST(WTF_WorkQueue, Simple)
         m_testCompleted.signal();
     });
 
+    EXPECT_GT(queue->refCount(), 1);
+
     m_testCompleted.wait(m_lock);
 
+    EXPECT_EQ(1, queue->refCount());
+
     EXPECT_TRUE(calledSimpleTest);
     EXPECT_TRUE(calledLongTest);
     EXPECT_TRUE(calledThirdTest);
 
-    EXPECT_EQ(m_functionCallOrder.size(), static_cast<size_t>(3));
+    EXPECT_EQ(static_cast<size_t>(3), m_functionCallOrder.size());
     EXPECT_STREQ(simpleTestLabel, m_functionCallOrder[0].c_str());
     EXPECT_STREQ(longTestLabel, m_functionCallOrder[1].c_str());
     EXPECT_STREQ(thirdTestLabel, m_functionCallOrder[2].c_str());
@@ -103,6 +109,11 @@ TEST(WTF_WorkQueue, TwoQueues)
     auto queue1 = WorkQueue::create("com.apple.WebKit.Test.twoQueues1");
     auto queue2 = WorkQueue::create("com.apple.WebKit.Test.twoQueues2");
 
+    int initialQueue1RefCount = queue1->refCount();
+    int initialQueue2RefCount = queue2->refCount();
+    EXPECT_EQ(1, initialQueue1RefCount);
+    EXPECT_EQ(1, initialQueue2RefCount);
+
     MutexLocker locker(m_lock);
     
     queue1->dispatch([&](void) {
@@ -132,14 +143,16 @@ TEST(WTF_WorkQueue, TwoQueues)
     EXPECT_TRUE(calledSimpleTest);
     EXPECT_FALSE(calledLongTest);
     EXPECT_TRUE(calledThirdTest);
+    EXPECT_EQ(1, queue1->refCount());
 
     m_testQueue2Completed.wait(m_lock);
 
     EXPECT_TRUE(calledSimpleTest);
     EXPECT_TRUE(calledLongTest);
     EXPECT_TRUE(calledThirdTest);
+    EXPECT_EQ(1, queue2->refCount());
 
-    EXPECT_EQ(m_functionCallOrder.size(), static_cast<size_t>(3));
+    EXPECT_EQ(static_cast<size_t>(3), m_functionCallOrder.size());
     EXPECT_STREQ(simpleTestLabel, m_functionCallOrder[0].c_str());
     EXPECT_STREQ(thirdTestLabel, m_functionCallOrder[1].c_str());
     EXPECT_STREQ(longTestLabel, m_functionCallOrder[2].c_str());
@@ -182,7 +195,7 @@ TEST(WTF_WorkQueue, DispatchAfter)
     EXPECT_TRUE(calledSimpleTest);
     EXPECT_TRUE(calledDispatchAfterTest);
 
-    EXPECT_EQ(m_functionCallOrder.size(), static_cast<size_t>(2));
+    EXPECT_EQ(static_cast<size_t>(2), m_functionCallOrder.size());
     EXPECT_STREQ(simpleTestLabel, m_functionCallOrder[0].c_str());
     EXPECT_STREQ(dispatchAfterLabel, m_functionCallOrder[1].c_str());
 }