Title: [133289] trunk/Source/WebKit2
Revision
133289
Author
commit-qu...@webkit.org
Date
2012-11-02 06:00:41 -0700 (Fri, 02 Nov 2012)

Log Message

[EFL][WK2] Use MutexLocker instead of lock()/unlock().
https://bugs.webkit.org/show_bug.cgi?id=101015

Patch by Byungwoo Lee <bw80....@samsung.com> on 2012-11-02
Reviewed by Kenneth Rohde Christiansen.

Instead of lock()/unlock(), use MutexLocker in WorkQueue::performWork()
and WorkQueue::performTimerWork().

The locking scope will be more clear and simple with using MutexLocker.

* Platform/efl/WorkQueueEfl.cpp:
(WorkQueue::performWork):
(WorkQueue::insertTimerWorkItem):
(WorkQueue::performTimerWork):
(WorkQueue::dispatchAfterDelay):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (133288 => 133289)


--- trunk/Source/WebKit2/ChangeLog	2012-11-02 12:16:22 UTC (rev 133288)
+++ trunk/Source/WebKit2/ChangeLog	2012-11-02 13:00:41 UTC (rev 133289)
@@ -1,3 +1,21 @@
+2012-11-02  Byungwoo Lee  <bw80....@samsung.com>
+
+        [EFL][WK2] Use MutexLocker instead of lock()/unlock().
+        https://bugs.webkit.org/show_bug.cgi?id=101015
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Instead of lock()/unlock(), use MutexLocker in WorkQueue::performWork()
+        and WorkQueue::performTimerWork().
+
+        The locking scope will be more clear and simple with using MutexLocker.
+
+        * Platform/efl/WorkQueueEfl.cpp:
+        (WorkQueue::performWork):
+        (WorkQueue::insertTimerWorkItem):
+        (WorkQueue::performTimerWork):
+        (WorkQueue::dispatchAfterDelay):
+
 2012-11-02  Mikhail Pozdnyakov  <mikhail.pozdnya...@intel.com>
 
         [EFL][WK2] Common ref and unref functions for EFL WK2 objects

Modified: trunk/Source/WebKit2/Platform/efl/WorkQueueEfl.cpp (133288 => 133289)


--- trunk/Source/WebKit2/Platform/efl/WorkQueueEfl.cpp	2012-11-02 12:16:22 UTC (rev 133288)
+++ trunk/Source/WebKit2/Platform/efl/WorkQueueEfl.cpp	2012-11-02 13:00:41 UTC (rev 133289)
@@ -68,18 +68,20 @@
 
 void WorkQueue::performWork()
 {
-    m_workItemQueueLock.lock();
-
-    while (!m_workItemQueue.isEmpty()) {
+    while (true) {
         Vector<Function<void()> > workItemQueue;
-        m_workItemQueue.swap(workItemQueue);
 
-        m_workItemQueueLock.unlock();
+        {
+            MutexLocker locker(m_workItemQueueLock);
+            if (m_workItemQueue.isEmpty())
+                return;
+
+            m_workItemQueue.swap(workItemQueue);
+        }
+
         for (size_t i = 0; i < workItemQueue.size(); ++i)
             workItemQueue[i]();
-        m_workItemQueueLock.lock();
     }
-    m_workItemQueueLock.unlock();
 }
 
 void WorkQueue::performFileDescriptorWork()
@@ -135,22 +137,23 @@
 
 void WorkQueue::performTimerWork()
 {
-    // Protects m_timerWorkItems.
-    m_timerWorkItemsLock.lock();
+    Vector<OwnPtr<TimerWorkItem> > timerWorkItems;
 
-    if (m_timerWorkItems.isEmpty()) {
-        m_timerWorkItemsLock.unlock();
-        return;
+    {
+        // Protects m_timerWorkItems.
+        MutexLocker locker(m_timerWorkItemsLock);
+        if (m_timerWorkItems.isEmpty())
+            return;
+
+        // Copies all the timer work items in m_timerWorkItems to local vector.
+        m_timerWorkItems.swap(timerWorkItems);
     }
 
     double current = currentTime();
-    Vector<OwnPtr<TimerWorkItem> > timerWorkItems;
 
-    // Copies all the timer work items in m_timerWorkItems to local vector.
-    m_timerWorkItems.swap(timerWorkItems);
-
     for (size_t i = 0; i < timerWorkItems.size(); ++i) {
         if (!timerWorkItems[i]->expired(current)) {
+            MutexLocker locker(m_timerWorkItemsLock);
             // If a timer work item does not expired, keep it to the m_timerWorkItems.
             // m_timerWorkItems should be ordered by expire time.
             insertTimerWorkItem(timerWorkItems[i].release());
@@ -158,14 +161,8 @@
         }
 
         // If a timer work item expired, dispatch the function of the work item.
-        // Before dispatching, m_timerWorkItemsLock should unlock for preventing deadlock,
-        // because it can be accessed inside the function of the timer work item dispatched.
-        m_timerWorkItemsLock.unlock();
         timerWorkItems[i]->dispatch();
-        m_timerWorkItemsLock.lock();
     }
-
-    m_timerWorkItemsLock.unlock();
 }
 
 void WorkQueue::sendMessageToThread(const char* message)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to