Changeset 161161 in webkit


Ignore:
Timestamp:
Dec 30, 2013 5:22:01 PM (10 years ago)
Author:
andersca@apple.com
Message:

Stop using ThreadCondition in BlockAllocator
https://bugs.webkit.org/show_bug.cgi?id=126313

Reviewed by Sam Weinig.

  • heap/BlockAllocator.cpp:

(JSC::BlockAllocator::~BlockAllocator):
(JSC::BlockAllocator::waitForDuration):
(JSC::BlockAllocator::blockFreeingThreadMain):

  • heap/BlockAllocator.h:

(JSC::BlockAllocator::deallocate):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r161159 r161161  
     12013-12-30  Anders Carlsson  <andersca@apple.com>
     2
     3        Stop using ThreadCondition in BlockAllocator
     4        https://bugs.webkit.org/show_bug.cgi?id=126313
     5
     6        Reviewed by Sam Weinig.
     7
     8        * heap/BlockAllocator.cpp:
     9        (JSC::BlockAllocator::~BlockAllocator):
     10        (JSC::BlockAllocator::waitForDuration):
     11        (JSC::BlockAllocator::blockFreeingThreadMain):
     12        * heap/BlockAllocator.h:
     13        (JSC::BlockAllocator::deallocate):
     14
    1152013-12-30  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/Source/JavaScriptCore/heap/BlockAllocator.cpp

    r157537 r161161  
    6262    releaseFreeRegions();
    6363    {
    64         MutexLocker locker(m_emptyRegionConditionLock);
     64        std::lock_guard<std::mutex> lock(m_emptyRegionConditionMutex);
    6565        m_blockFreeingThreadShouldQuit = true;
    66         m_emptyRegionCondition.broadcast();
     66        m_emptyRegionCondition.notify_all();
    6767    }
    6868    if (m_blockFreeingThread)
     
    102102}
    103103
    104 void BlockAllocator::waitForRelativeTimeWhileHoldingLock(double relative)
     104void BlockAllocator::waitForDuration(std::chrono::milliseconds duration)
    105105{
     106    std::unique_lock<std::mutex> lock(m_emptyRegionConditionMutex);
     107
     108    // If this returns early, that's fine, so long as it doesn't do it too
     109    // frequently. It would only be a bug if this function failed to return
     110    // when it was asked to do so.
    106111    if (m_blockFreeingThreadShouldQuit)
    107112        return;
    108113
    109     m_emptyRegionCondition.timedWait(m_emptyRegionConditionLock, currentTime() + relative);
    110 }
    111 
    112 void BlockAllocator::waitForRelativeTime(double relative)
    113 {
    114     // If this returns early, that's fine, so long as it doesn't do it too
    115     // frequently. It would only be a bug if this function failed to return
    116     // when it was asked to do so.
    117    
    118     MutexLocker locker(m_emptyRegionConditionLock);
    119     waitForRelativeTimeWhileHoldingLock(relative);
     114    m_emptyRegionCondition.wait_for(lock, duration);
    120115}
    121116
     
    131126        // Generally wait for one second before scavenging free blocks. This
    132127        // may return early, particularly when we're being asked to quit.
    133         waitForRelativeTime(1.0);
     128        waitForDuration(std::chrono::seconds(1));
    134129        if (m_blockFreeingThreadShouldQuit)
    135130            break;
     
    142137        // Sleep until there is actually work to do rather than waking up every second to check.
    143138        {
    144             MutexLocker locker(m_emptyRegionConditionLock);
     139            std::unique_lock<std::mutex> lock(m_emptyRegionConditionMutex);
    145140            SpinLockHolder regionLocker(&m_regionLock);
    146141            while (!m_numberOfEmptyRegions && !m_blockFreeingThreadShouldQuit) {
    147142                m_regionLock.Unlock();
    148                 m_emptyRegionCondition.wait(m_emptyRegionConditionLock);
     143                m_emptyRegionCondition.wait(lock);
    149144                m_regionLock.Lock();
    150145            }
  • trunk/Source/JavaScriptCore/heap/BlockAllocator.h

    r157653 r161161  
    3030#include "HeapBlock.h"
    3131#include "Region.h"
     32#include <mutex>
    3233#include <wtf/DoublyLinkedList.h>
    3334#include <wtf/Forward.h>
     
    6162
    6263private:
    63     void waitForRelativeTimeWhileHoldingLock(double relative);
    64     void waitForRelativeTime(double relative);
     64    void waitForDuration(std::chrono::milliseconds);
    6565
    6666    friend ThreadIdentifier createBlockFreeingThread(BlockAllocator*);
     
    106106    bool m_blockFreeingThreadShouldQuit;
    107107    SpinLock m_regionLock;
    108     Mutex m_emptyRegionConditionLock;
    109     ThreadCondition m_emptyRegionCondition;
     108    std::mutex m_emptyRegionConditionMutex;
     109    std::condition_variable m_emptyRegionCondition;
    110110    ThreadIdentifier m_blockFreeingThread;
    111111};
     
    200200
    201201    if (shouldWakeBlockFreeingThread) {
    202         MutexLocker mutexLocker(m_emptyRegionConditionLock);
    203         m_emptyRegionCondition.signal();
     202        std::lock_guard<std::mutex> lock(m_emptyRegionConditionMutex);
     203        m_emptyRegionCondition.notify_one();
    204204    }
    205205
Note: See TracChangeset for help on using the changeset viewer.