Changeset 188444 in webkit


Ignore:
Timestamp:
Aug 13, 2015, 11:46:46 PM (10 years ago)
Author:
[email protected]
Message:

Use WTF::Lock and WTF::Condition instead of WTF::Mutex, WTF::ThreadCondition, std::mutex, and std::condition_variable
https://bugs.webkit.org/show_bug.cgi?id=147999

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • API/JSVirtualMachine.mm:

(initWrapperCache):
(+[JSVMWrapperCache addWrapper:forJSContextGroupRef:]):
(+[JSVMWrapperCache wrapperForJSContextGroupRef:]):
(wrapperCacheMutex): Deleted.

  • bytecode/SamplingTool.cpp:

(JSC::SamplingTool::doRun):
(JSC::SamplingTool::notifyOfScope):

  • bytecode/SamplingTool.h:
  • dfg/DFGThreadData.h:
  • dfg/DFGWorklist.cpp:

(JSC::DFG::Worklist::~Worklist):
(JSC::DFG::Worklist::isActiveForVM):
(JSC::DFG::Worklist::enqueue):
(JSC::DFG::Worklist::compilationState):
(JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady):
(JSC::DFG::Worklist::removeAllReadyPlansForVM):
(JSC::DFG::Worklist::completeAllReadyPlansForVM):
(JSC::DFG::Worklist::visitWeakReferences):
(JSC::DFG::Worklist::removeDeadPlans):
(JSC::DFG::Worklist::queueLength):
(JSC::DFG::Worklist::dump):
(JSC::DFG::Worklist::runThread):

  • dfg/DFGWorklist.h:
  • disassembler/Disassembler.cpp:
  • heap/CopiedSpace.cpp:

(JSC::CopiedSpace::doneFillingBlock):
(JSC::CopiedSpace::doneCopying):

  • heap/CopiedSpace.h:
  • heap/CopiedSpaceInlines.h:

(JSC::CopiedSpace::recycleBorrowedBlock):
(JSC::CopiedSpace::allocateBlockForCopyingPhase):

  • heap/GCThread.cpp:

(JSC::GCThread::waitForNextPhase):
(JSC::GCThread::gcThreadMain):

  • heap/GCThreadSharedData.cpp:

(JSC::GCThreadSharedData::GCThreadSharedData):
(JSC::GCThreadSharedData::~GCThreadSharedData):
(JSC::GCThreadSharedData::startNextPhase):
(JSC::GCThreadSharedData::endCurrentPhase):
(JSC::GCThreadSharedData::didStartMarking):
(JSC::GCThreadSharedData::didFinishMarking):

  • heap/GCThreadSharedData.h:
  • heap/HeapTimer.h:
  • heap/MachineStackMarker.cpp:

(JSC::ActiveMachineThreadsManager::Locker::Locker):
(JSC::ActiveMachineThreadsManager::add):
(JSC::ActiveMachineThreadsManager::remove):
(JSC::ActiveMachineThreadsManager::ActiveMachineThreadsManager):
(JSC::MachineThreads::~MachineThreads):
(JSC::MachineThreads::addCurrentThread):
(JSC::MachineThreads::removeThreadIfFound):
(JSC::MachineThreads::tryCopyOtherThreadStack):
(JSC::MachineThreads::tryCopyOtherThreadStacks):
(JSC::MachineThreads::gatherConservativeRoots):

  • heap/MachineStackMarker.h:
  • heap/SlotVisitor.cpp:

(JSC::SlotVisitor::donateKnownParallel):
(JSC::SlotVisitor::drain):
(JSC::SlotVisitor::drainFromShared):
(JSC::SlotVisitor::mergeOpaqueRoots):

  • heap/SlotVisitorInlines.h:

(JSC::SlotVisitor::containsOpaqueRootTriState):

  • inspector/remote/RemoteInspectorDebuggableConnection.h:
  • inspector/remote/RemoteInspectorDebuggableConnection.mm:

(Inspector::RemoteInspectorHandleRunSourceGlobal):
(Inspector::RemoteInspectorQueueTaskOnGlobalQueue):
(Inspector::RemoteInspectorInitializeGlobalQueue):
(Inspector::RemoteInspectorHandleRunSourceWithInfo):
(Inspector::RemoteInspectorDebuggableConnection::setup):
(Inspector::RemoteInspectorDebuggableConnection::closeFromDebuggable):
(Inspector::RemoteInspectorDebuggableConnection::close):
(Inspector::RemoteInspectorDebuggableConnection::sendMessageToBackend):
(Inspector::RemoteInspectorDebuggableConnection::queueTaskOnPrivateRunLoop):

  • interpreter/JSStack.cpp:

(JSC::JSStack::JSStack):
(JSC::JSStack::releaseExcessCapacity):
(JSC::JSStack::addToCommittedByteCount):
(JSC::JSStack::committedByteCount):
(JSC::stackStatisticsMutex): Deleted.
(JSC::JSStack::initializeThreading): Deleted.

  • interpreter/JSStack.h:

(JSC::JSStack::gatherConservativeRoots):
(JSC::JSStack::sanitizeStack):
(JSC::JSStack::size):
(JSC::JSStack::initializeThreading): Deleted.

  • jit/ExecutableAllocator.cpp:

(JSC::DemandExecutableAllocator::DemandExecutableAllocator):
(JSC::DemandExecutableAllocator::~DemandExecutableAllocator):
(JSC::DemandExecutableAllocator::bytesAllocatedByAllAllocators):
(JSC::DemandExecutableAllocator::bytesCommittedByAllocactors):
(JSC::DemandExecutableAllocator::dumpProfileFromAllAllocators):
(JSC::DemandExecutableAllocator::allocators):
(JSC::DemandExecutableAllocator::allocatorsMutex):

  • jit/JITThunks.cpp:

(JSC::JITThunks::ctiStub):

  • jit/JITThunks.h:
  • profiler/ProfilerDatabase.cpp:

(JSC::Profiler::Database::ensureBytecodesFor):
(JSC::Profiler::Database::notifyDestruction):

  • profiler/ProfilerDatabase.h:
  • runtime/InitializeThreading.cpp:

(JSC::initializeThreading):

  • runtime/JSLock.cpp:

(JSC::GlobalJSLock::GlobalJSLock):
(JSC::GlobalJSLock::~GlobalJSLock):
(JSC::JSLockHolder::JSLockHolder):
(JSC::GlobalJSLock::initialize): Deleted.

  • runtime/JSLock.h:

Source/WTF:

  • wtf/Condition.h: "using WTF::Condition".
  • wtf/Lock.h:

(WTF::LockBase::lock):
(WTF::LockBase::tryLock): Add tryLock() because it turns out that we use it sometimes.
(WTF::LockBase::try_lock): unique_lock needs this.
(WTF::LockBase::unlock):

Location:
trunk/Source
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSVirtualMachine.mm

    r174110 r188444  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3737#import "SlotVisitorInlines.h"
    3838#import <mutex>
     39#import <wtf/Lock.h>
    3940#import <wtf/NeverDestroyed.h>
    4041#import <wtf/spi/cocoa/NSMapTableSPI.h>
     
    4243static NSMapTable *globalWrapperCache = 0;
    4344
    44 static std::mutex& wrapperCacheMutex()
    45 {
    46     static NeverDestroyed<std::mutex> mutex;
    47 
    48     return mutex;
    49 }
     45static StaticLock wrapperCacheMutex;
    5046
    5147static void initWrapperCache()
     
    7369+ (void)addWrapper:(JSVirtualMachine *)wrapper forJSContextGroupRef:(JSContextGroupRef)group
    7470{
    75     std::lock_guard<std::mutex> lock(wrapperCacheMutex());
     71    std::lock_guard<StaticLock> lock(wrapperCacheMutex);
    7672    NSMapInsert(wrapperCache(), group, wrapper);
    7773}
     
    7975+ (JSVirtualMachine *)wrapperForJSContextGroupRef:(JSContextGroupRef)group
    8076{
    81     std::lock_guard<std::mutex> lock(wrapperCacheMutex());
     77    std::lock_guard<StaticLock> lock(wrapperCacheMutex);
    8278    return static_cast<JSVirtualMachine *>(NSMapGet(wrapperCache(), group));
    8379}
  • trunk/Source/JavaScriptCore/ChangeLog

    r188436 r188444  
     12015-08-13  Filip Pizlo  <[email protected]>
     2
     3        Use WTF::Lock and WTF::Condition instead of WTF::Mutex, WTF::ThreadCondition, std::mutex, and std::condition_variable
     4        https://bugs.webkit.org/show_bug.cgi?id=147999
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * API/JSVirtualMachine.mm:
     9        (initWrapperCache):
     10        (+[JSVMWrapperCache addWrapper:forJSContextGroupRef:]):
     11        (+[JSVMWrapperCache wrapperForJSContextGroupRef:]):
     12        (wrapperCacheMutex): Deleted.
     13        * bytecode/SamplingTool.cpp:
     14        (JSC::SamplingTool::doRun):
     15        (JSC::SamplingTool::notifyOfScope):
     16        * bytecode/SamplingTool.h:
     17        * dfg/DFGThreadData.h:
     18        * dfg/DFGWorklist.cpp:
     19        (JSC::DFG::Worklist::~Worklist):
     20        (JSC::DFG::Worklist::isActiveForVM):
     21        (JSC::DFG::Worklist::enqueue):
     22        (JSC::DFG::Worklist::compilationState):
     23        (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady):
     24        (JSC::DFG::Worklist::removeAllReadyPlansForVM):
     25        (JSC::DFG::Worklist::completeAllReadyPlansForVM):
     26        (JSC::DFG::Worklist::visitWeakReferences):
     27        (JSC::DFG::Worklist::removeDeadPlans):
     28        (JSC::DFG::Worklist::queueLength):
     29        (JSC::DFG::Worklist::dump):
     30        (JSC::DFG::Worklist::runThread):
     31        * dfg/DFGWorklist.h:
     32        * disassembler/Disassembler.cpp:
     33        * heap/CopiedSpace.cpp:
     34        (JSC::CopiedSpace::doneFillingBlock):
     35        (JSC::CopiedSpace::doneCopying):
     36        * heap/CopiedSpace.h:
     37        * heap/CopiedSpaceInlines.h:
     38        (JSC::CopiedSpace::recycleBorrowedBlock):
     39        (JSC::CopiedSpace::allocateBlockForCopyingPhase):
     40        * heap/GCThread.cpp:
     41        (JSC::GCThread::waitForNextPhase):
     42        (JSC::GCThread::gcThreadMain):
     43        * heap/GCThreadSharedData.cpp:
     44        (JSC::GCThreadSharedData::GCThreadSharedData):
     45        (JSC::GCThreadSharedData::~GCThreadSharedData):
     46        (JSC::GCThreadSharedData::startNextPhase):
     47        (JSC::GCThreadSharedData::endCurrentPhase):
     48        (JSC::GCThreadSharedData::didStartMarking):
     49        (JSC::GCThreadSharedData::didFinishMarking):
     50        * heap/GCThreadSharedData.h:
     51        * heap/HeapTimer.h:
     52        * heap/MachineStackMarker.cpp:
     53        (JSC::ActiveMachineThreadsManager::Locker::Locker):
     54        (JSC::ActiveMachineThreadsManager::add):
     55        (JSC::ActiveMachineThreadsManager::remove):
     56        (JSC::ActiveMachineThreadsManager::ActiveMachineThreadsManager):
     57        (JSC::MachineThreads::~MachineThreads):
     58        (JSC::MachineThreads::addCurrentThread):
     59        (JSC::MachineThreads::removeThreadIfFound):
     60        (JSC::MachineThreads::tryCopyOtherThreadStack):
     61        (JSC::MachineThreads::tryCopyOtherThreadStacks):
     62        (JSC::MachineThreads::gatherConservativeRoots):
     63        * heap/MachineStackMarker.h:
     64        * heap/SlotVisitor.cpp:
     65        (JSC::SlotVisitor::donateKnownParallel):
     66        (JSC::SlotVisitor::drain):
     67        (JSC::SlotVisitor::drainFromShared):
     68        (JSC::SlotVisitor::mergeOpaqueRoots):
     69        * heap/SlotVisitorInlines.h:
     70        (JSC::SlotVisitor::containsOpaqueRootTriState):
     71        * inspector/remote/RemoteInspectorDebuggableConnection.h:
     72        * inspector/remote/RemoteInspectorDebuggableConnection.mm:
     73        (Inspector::RemoteInspectorHandleRunSourceGlobal):
     74        (Inspector::RemoteInspectorQueueTaskOnGlobalQueue):
     75        (Inspector::RemoteInspectorInitializeGlobalQueue):
     76        (Inspector::RemoteInspectorHandleRunSourceWithInfo):
     77        (Inspector::RemoteInspectorDebuggableConnection::setup):
     78        (Inspector::RemoteInspectorDebuggableConnection::closeFromDebuggable):
     79        (Inspector::RemoteInspectorDebuggableConnection::close):
     80        (Inspector::RemoteInspectorDebuggableConnection::sendMessageToBackend):
     81        (Inspector::RemoteInspectorDebuggableConnection::queueTaskOnPrivateRunLoop):
     82        * interpreter/JSStack.cpp:
     83        (JSC::JSStack::JSStack):
     84        (JSC::JSStack::releaseExcessCapacity):
     85        (JSC::JSStack::addToCommittedByteCount):
     86        (JSC::JSStack::committedByteCount):
     87        (JSC::stackStatisticsMutex): Deleted.
     88        (JSC::JSStack::initializeThreading): Deleted.
     89        * interpreter/JSStack.h:
     90        (JSC::JSStack::gatherConservativeRoots):
     91        (JSC::JSStack::sanitizeStack):
     92        (JSC::JSStack::size):
     93        (JSC::JSStack::initializeThreading): Deleted.
     94        * jit/ExecutableAllocator.cpp:
     95        (JSC::DemandExecutableAllocator::DemandExecutableAllocator):
     96        (JSC::DemandExecutableAllocator::~DemandExecutableAllocator):
     97        (JSC::DemandExecutableAllocator::bytesAllocatedByAllAllocators):
     98        (JSC::DemandExecutableAllocator::bytesCommittedByAllocactors):
     99        (JSC::DemandExecutableAllocator::dumpProfileFromAllAllocators):
     100        (JSC::DemandExecutableAllocator::allocators):
     101        (JSC::DemandExecutableAllocator::allocatorsMutex):
     102        * jit/JITThunks.cpp:
     103        (JSC::JITThunks::ctiStub):
     104        * jit/JITThunks.h:
     105        * profiler/ProfilerDatabase.cpp:
     106        (JSC::Profiler::Database::ensureBytecodesFor):
     107        (JSC::Profiler::Database::notifyDestruction):
     108        * profiler/ProfilerDatabase.h:
     109        * runtime/InitializeThreading.cpp:
     110        (JSC::initializeThreading):
     111        * runtime/JSLock.cpp:
     112        (JSC::GlobalJSLock::GlobalJSLock):
     113        (JSC::GlobalJSLock::~GlobalJSLock):
     114        (JSC::JSLockHolder::JSLockHolder):
     115        (JSC::GlobalJSLock::initialize): Deleted.
     116        * runtime/JSLock.h:
     117
    11182015-08-13  Commit Queue  <[email protected]>
    2119
  • trunk/Source/JavaScriptCore/bytecode/SamplingTool.cpp

    r188002 r188444  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    286286#if ENABLE(CODEBLOCK_SAMPLING)
    287287    if (CodeBlock* codeBlock = sample.codeBlock()) {
    288         MutexLocker locker(m_scriptSampleMapMutex);
     288        LockHolder locker(m_scriptSampleMapMutex);
    289289        ScriptSampleRecord* record = m_scopeSampleMap->get(codeBlock->ownerExecutable());
    290290        ASSERT(record);
     
    302302{
    303303#if ENABLE(CODEBLOCK_SAMPLING)
    304     MutexLocker locker(m_scriptSampleMapMutex);
     304    LockHolder locker(m_scriptSampleMapMutex);
    305305    m_scopeSampleMap->set(script, adoptPtr(new ScriptSampleRecord(vm, script)));
    306306#else
  • trunk/Source/JavaScriptCore/bytecode/SamplingTool.h

    r188002 r188444  
    11/*
    2  * Copyright (C) 2008, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636#include <wtf/Atomics.h>
    3737#include <wtf/HashMap.h>
     38#include <wtf/Lock.h>
    3839#include <wtf/MainThread.h>
    3940#include <wtf/Spectrum.h>
     
    339340       
    340341#if ENABLE(CODEBLOCK_SAMPLING)
    341         Mutex m_scriptSampleMapMutex;
     342        Lock m_scriptSampleMapMutex;
    342343        std::unique_ptr<ScriptSampleRecordMap> m_scopeSampleMap;
    343344#endif
  • trunk/Source/JavaScriptCore/dfg/DFGThreadData.h

    r188002 r188444  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#if ENABLE(DFG_JIT)
    3030
     31#include <wtf/Lock.h>
    3132#include <wtf/Threading.h>
    32 #include <wtf/ThreadingPrimitives.h>
    3333
    3434namespace JSC { namespace DFG {
     
    4949    Worklist* m_worklist;
    5050    ThreadIdentifier m_identifier;
    51     Mutex m_rightToRun;
     51    Lock m_rightToRun;
    5252    Safepoint* m_safepoint;
    5353};
  • trunk/Source/JavaScriptCore/dfg/DFGWorklist.cpp

    r188002 r188444  
    4747{
    4848    {
    49         MutexLocker locker(m_lock);
     49        LockHolder locker(m_lock);
    5050        for (unsigned i = m_threads.size(); i--;)
    5151            m_queue.append(nullptr); // Use null plan to indicate that we want the thread to terminate.
    52         m_planEnqueued.broadcast();
     52        m_planEnqueued.notifyAll();
    5353    }
    5454    for (unsigned i = m_threads.size(); i--;)
     
    7878bool Worklist::isActiveForVM(VM& vm) const
    7979{
    80     MutexLocker locker(m_lock);
     80    LockHolder locker(m_lock);
    8181    PlanMap::const_iterator end = m_plans.end();
    8282    for (PlanMap::const_iterator iter = m_plans.begin(); iter != end; ++iter) {
     
    9090{
    9191    RefPtr<Plan> plan = passedPlan;
    92     MutexLocker locker(m_lock);
     92    LockHolder locker(m_lock);
    9393    if (Options::verboseCompilationQueue()) {
    9494        dump(locker, WTF::dataFile());
     
    9898    m_plans.add(plan->key(), plan);
    9999    m_queue.append(plan);
    100     m_planEnqueued.signal();
     100    m_planEnqueued.notifyOne();
    101101}
    102102
    103103Worklist::State Worklist::compilationState(CompilationKey key)
    104104{
    105     MutexLocker locker(m_lock);
     105    LockHolder locker(m_lock);
    106106    PlanMap::iterator iter = m_plans.find(key);
    107107    if (iter == m_plans.end())
     
    119119    // be adding plans, our VM will not be.
    120120   
    121     MutexLocker locker(m_lock);
     121    LockHolder locker(m_lock);
    122122   
    123123    if (Options::verboseCompilationQueue()) {
     
    148148{
    149149    DeferGC deferGC(vm.heap);
    150     MutexLocker locker(m_lock);
     150    LockHolder locker(m_lock);
    151151    for (size_t i = 0; i < m_readyPlans.size(); ++i) {
    152152        RefPtr<Plan> plan = m_readyPlans[i];
     
    193193   
    194194    if (!!requestedKey && resultingState == NotKnown) {
    195         MutexLocker locker(m_lock);
     195        LockHolder locker(m_lock);
    196196        if (m_plans.contains(requestedKey))
    197197            resultingState = Compiling;
     
    226226    VM* vm = visitor.heap()->vm();
    227227    {
    228         MutexLocker locker(m_lock);
     228        LockHolder locker(m_lock);
    229229        for (PlanMap::iterator iter = m_plans.begin(); iter != m_plans.end(); ++iter) {
    230230            Plan* plan = iter->value.get();
     
    249249{
    250250    {
    251         MutexLocker locker(m_lock);
     251        LockHolder locker(m_lock);
    252252        HashSet<CompilationKey> deadPlanKeys;
    253253        for (PlanMap::iterator iter = m_plans.begin(); iter != m_plans.end(); ++iter) {
     
    296296size_t Worklist::queueLength()
    297297{
    298     MutexLocker locker(m_lock);
     298    LockHolder locker(m_lock);
    299299    return m_queue.size();
    300300}
     
    302302void Worklist::dump(PrintStream& out) const
    303303{
    304     MutexLocker locker(m_lock);
     304    LockHolder locker(m_lock);
    305305    dump(locker, out);
    306306}
    307307
    308 void Worklist::dump(const MutexLocker&, PrintStream& out) const
     308void Worklist::dump(const LockHolder&, PrintStream& out) const
    309309{
    310310    out.print(
     
    326326        RefPtr<Plan> plan;
    327327        {
    328             MutexLocker locker(m_lock);
     328            LockHolder locker(m_lock);
    329329            while (m_queue.isEmpty())
    330330                m_planEnqueued.wait(m_lock);
     
    342342       
    343343        {
    344             MutexLocker locker(data->m_rightToRun);
     344            LockHolder locker(data->m_rightToRun);
    345345            {
    346                 MutexLocker locker(m_lock);
     346                LockHolder locker(m_lock);
    347347                if (plan->stage == Plan::Cancelled) {
    348348                    m_numberOfActiveThreads--;
     
    360360           
    361361            {
    362                 MutexLocker locker(m_lock);
     362                LockHolder locker(m_lock);
    363363                if (plan->stage == Plan::Cancelled) {
    364364                    m_numberOfActiveThreads--;
     
    371371
    372372        {
    373             MutexLocker locker(m_lock);
     373            LockHolder locker(m_lock);
    374374           
    375375            // We could have been cancelled between releasing rightToRun and acquiring m_lock.
     
    389389            m_readyPlans.append(plan);
    390390           
    391             m_planCompiled.broadcast();
     391            m_planCompiled.notifyAll();
    392392            m_numberOfActiveThreads--;
    393393        }
  • trunk/Source/JavaScriptCore/dfg/DFGWorklist.h

    r188002 r188444  
    3131#include "DFGPlan.h"
    3232#include "DFGThreadData.h"
     33#include <wtf/Condition.h>
    3334#include <wtf/Deque.h>
    3435#include <wtf/HashMap.h>
     36#include <wtf/Lock.h>
    3537#include <wtf/Noncopyable.h>
    36 #include <wtf/ThreadingPrimitives.h>
    3738
    3839namespace JSC {
     
    8687    void removeAllReadyPlansForVM(VM&, Vector<RefPtr<Plan>, 8>&);
    8788
    88     void dump(const MutexLocker&, PrintStream&) const;
     89    void dump(const LockHolder&, PrintStream&) const;
    8990   
    9091    CString m_threadName;
     
    104105    Vector<RefPtr<Plan>, 16> m_readyPlans;
    105106
    106     Mutex m_suspensionLock;
     107    Lock m_suspensionLock;
    107108   
    108     mutable Mutex m_lock;
    109     ThreadCondition m_planEnqueued;
    110     ThreadCondition m_planCompiled;
     109    mutable Lock m_lock;
     110    Condition m_planEnqueued;
     111    Condition m_planCompiled;
    111112   
    112113    Vector<std::unique_ptr<ThreadData>> m_threads;
  • trunk/Source/JavaScriptCore/disassembler/Disassembler.cpp

    r188002 r188444  
    2828
    2929#include "MacroAssemblerCodeRef.h"
     30#include <wtf/Condition.h>
    3031#include <wtf/DataLog.h>
    3132#include <wtf/Deque.h>
     33#include <wtf/Lock.h>
    3234#include <wtf/NeverDestroyed.h>
    3335#include <wtf/StringPrintStream.h>
    3436#include <wtf/Threading.h>
    35 #include <wtf/ThreadingPrimitives.h>
    3637
    3738namespace JSC {
     
    7980    void enqueue(std::unique_ptr<DisassemblyTask> task)
    8081    {
    81         MutexLocker locker(m_lock);
     82        LockHolder locker(m_lock);
    8283        m_queue.append(WTF::move(task));
    83         m_condition.broadcast();
     84        m_condition.notifyAll();
    8485    }
    8586   
    8687    void waitUntilEmpty()
    8788    {
    88         MutexLocker locker(m_lock);
     89        LockHolder locker(m_lock);
    8990        while (!m_queue.isEmpty() || m_working)
    9091            m_condition.wait(m_lock);
     
    9798            std::unique_ptr<DisassemblyTask> task;
    9899            {
    99                 MutexLocker locker(m_lock);
     100                LockHolder locker(m_lock);
    100101                m_working = false;
    101                 m_condition.broadcast();
     102                m_condition.notifyAll();
    102103                while (m_queue.isEmpty())
    103104                    m_condition.wait(m_lock);
     
    113114    }
    114115   
    115     Mutex m_lock;
    116     ThreadCondition m_condition;
     116    Lock m_lock;
     117    Condition m_condition;
    117118    Deque<std::unique_ptr<DisassemblyTask>> m_queue;
    118119    bool m_working { false };
  • trunk/Source/JavaScriptCore/heap/CopiedSpace.cpp

    r188169 r188444  
    199199
    200200    {
    201         MutexLocker locker(m_loanedBlocksLock);
     201        LockHolder locker(m_loanedBlocksLock);
    202202        ASSERT(m_numberOfLoanedBlocks > 0);
    203203        ASSERT(m_inCopyingPhase);
    204204        m_numberOfLoanedBlocks--;
    205205        if (!m_numberOfLoanedBlocks)
    206             m_loanedBlocksCondition.signal();
     206            m_loanedBlocksCondition.notifyOne();
    207207    }
    208208}
     
    232232{
    233233    {
    234         MutexLocker locker(m_loanedBlocksLock);
     234        LockHolder locker(m_loanedBlocksLock);
    235235        while (m_numberOfLoanedBlocks > 0)
    236236            m_loanedBlocksCondition.wait(m_loanedBlocksLock);
  • trunk/Source/JavaScriptCore/heap/CopiedSpace.h

    r188169 r188444  
    3232#include <wtf/Assertions.h>
    3333#include <wtf/CheckedBoolean.h>
     34#include <wtf/Condition.h>
    3435#include <wtf/DoublyLinkedList.h>
    3536#include <wtf/HashSet.h>
     
    3839#include <wtf/PageBlock.h>
    3940#include <wtf/StdLibExtras.h>
    40 #include <wtf/ThreadingPrimitives.h>
    4141
    4242namespace JSC {
     
    139139    bool m_shouldDoCopyPhase;
    140140
    141     Mutex m_loanedBlocksLock;
    142     ThreadCondition m_loanedBlocksCondition;
     141    Lock m_loanedBlocksLock;
     142    Condition m_loanedBlocksCondition;
    143143    size_t m_numberOfLoanedBlocks;
    144144   
  • trunk/Source/JavaScriptCore/heap/CopiedSpaceInlines.h

    r188169 r188444  
    114114
    115115    {
    116         MutexLocker locker(m_loanedBlocksLock);
     116        LockHolder locker(m_loanedBlocksLock);
    117117        ASSERT(m_numberOfLoanedBlocks > 0);
    118118        ASSERT(m_inCopyingPhase);
    119119        m_numberOfLoanedBlocks--;
    120120        if (!m_numberOfLoanedBlocks)
    121             m_loanedBlocksCondition.signal();
     121            m_loanedBlocksCondition.notifyOne();
    122122    }
    123123}
     
    129129
    130130    {
    131         MutexLocker locker(m_loanedBlocksLock);
     131        LockHolder locker(m_loanedBlocksLock);
    132132        m_numberOfLoanedBlocks++;
    133133    }
  • trunk/Source/JavaScriptCore/heap/GCThread.cpp

    r183005 r188444  
    7070GCPhase GCThread::waitForNextPhase()
    7171{
    72     std::unique_lock<std::mutex> lock(m_shared.m_phaseMutex);
     72    std::unique_lock<Lock> lock(m_shared.m_phaseMutex);
    7373    m_shared.m_phaseConditionVariable.wait(lock, [this] { return !m_shared.m_gcThreadsShouldWait; });
    7474
    7575    m_shared.m_numberOfActiveGCThreads--;
    7676    if (!m_shared.m_numberOfActiveGCThreads)
    77         m_shared.m_activityConditionVariable.notify_one();
     77        m_shared.m_activityConditionVariable.notifyOne();
    7878
    7979    m_shared.m_phaseConditionVariable.wait(lock, [this] { return m_shared.m_currentPhase != NoPhase; });
     
    9191    // creating this thread. We aren't guaranteed to have a valid threadID until the main thread releases this lock.
    9292    {
    93         std::lock_guard<std::mutex> lock(m_shared.m_phaseMutex);
     93        std::lock_guard<Lock> lock(m_shared.m_phaseMutex);
    9494    }
    9595    {
  • trunk/Source/JavaScriptCore/heap/GCThreadSharedData.cpp

    r188169 r188444  
    11/*
    2  * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2011, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8484#if ENABLE(PARALLEL_GC)
    8585    // Grab the lock so the new GC threads can be properly initialized before they start running.
    86     std::unique_lock<std::mutex> lock(m_phaseMutex);
     86    std::unique_lock<Lock> lock(m_phaseMutex);
    8787    for (unsigned i = 1; i < Options::numberOfGCMarkers(); ++i) {
    8888        m_numberOfActiveGCThreads++;
     
    103103    // Destroy our marking threads.
    104104    {
    105         std::lock_guard<std::mutex> markingLock(m_markingMutex);
    106         std::lock_guard<std::mutex> phaseLock(m_phaseMutex);
     105        std::lock_guard<Lock> markingLock(m_markingMutex);
     106        std::lock_guard<Lock> phaseLock(m_phaseMutex);
    107107        ASSERT(m_currentPhase == NoPhase);
    108108        m_parallelMarkersShouldExit = true;
    109109        m_gcThreadsShouldWait = false;
    110110        m_currentPhase = Exit;
    111         m_phaseConditionVariable.notify_all();
     111        m_phaseConditionVariable.notifyAll();
    112112    }
    113113    for (unsigned i = 0; i < m_gcThreads.size(); ++i) {
     
    132132void GCThreadSharedData::startNextPhase(GCPhase phase)
    133133{
    134     std::lock_guard<std::mutex> lock(m_phaseMutex);
     134    std::lock_guard<Lock> lock(m_phaseMutex);
    135135    ASSERT(!m_gcThreadsShouldWait);
    136136    ASSERT(m_currentPhase == NoPhase);
    137137    m_gcThreadsShouldWait = true;
    138138    m_currentPhase = phase;
    139     m_phaseConditionVariable.notify_all();
     139    m_phaseConditionVariable.notifyAll();
    140140}
    141141
     
    143143{
    144144    ASSERT(m_gcThreadsShouldWait);
    145     std::unique_lock<std::mutex> lock(m_phaseMutex);
     145    std::unique_lock<Lock> lock(m_phaseMutex);
    146146    m_currentPhase = NoPhase;
    147147    m_gcThreadsShouldWait = false;
    148     m_phaseConditionVariable.notify_all();
     148    m_phaseConditionVariable.notifyAll();
    149149    m_activityConditionVariable.wait(lock, [this] { return !m_numberOfActiveGCThreads; });
    150150}
     
    159159#endif
    160160}
    161     std::lock_guard<std::mutex> lock(m_markingMutex);
     161    std::lock_guard<Lock> lock(m_markingMutex);
    162162    m_parallelMarkersShouldExit = false;
    163163    startNextPhase(Mark);
     
    167167{
    168168    {
    169         std::lock_guard<std::mutex> lock(m_markingMutex);
     169        std::lock_guard<Lock> lock(m_markingMutex);
    170170        m_parallelMarkersShouldExit = true;
    171         m_markingConditionVariable.notify_all();
     171        m_markingConditionVariable.notifyAll();
    172172    }
    173173
  • trunk/Source/JavaScriptCore/heap/GCThreadSharedData.h

    r188169 r188444  
    11/*
    2  * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2011, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3333#include "WeakReferenceHarvester.h"
    3434#include <condition_variable>
     35#include <wtf/Condition.h>
    3536#include <wtf/HashSet.h>
    3637#include <wtf/Lock.h>
     
    8990    Vector<GCThread*> m_gcThreads;
    9091
    91     std::mutex m_markingMutex;
    92     std::condition_variable m_markingConditionVariable;
     92    Lock m_markingMutex;
     93    Condition m_markingConditionVariable;
    9394    MarkStackArray m_sharedMarkStack;
    9495    unsigned m_numberOfActiveParallelMarkers;
    9596    bool m_parallelMarkersShouldExit;
    9697
    97     std::mutex m_opaqueRootsMutex;
     98    Lock m_opaqueRootsMutex;
    9899    HashSet<void*> m_opaqueRoots;
    99100
     
    103104    static const size_t s_blockFragmentLength = 32;
    104105
    105     std::mutex m_phaseMutex;
    106     std::condition_variable m_phaseConditionVariable;
    107     std::condition_variable m_activityConditionVariable;
     106    Lock m_phaseMutex;
     107    Condition m_phaseConditionVariable;
     108    Condition m_activityConditionVariable;
    108109    unsigned m_numberOfActiveGCThreads;
    109110    bool m_gcThreadsShouldWait;
  • trunk/Source/JavaScriptCore/heap/HeapTimer.h

    r188002 r188444  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define HeapTimer_h
    2828
     29#include <wtf/Lock.h>
    2930#include <wtf/RetainPtr.h>
    3031#include <wtf/Threading.h>
     
    6061    CFRunLoopTimerContext m_context;
    6162
    62     Mutex m_shutdownMutex;
     63    Lock m_shutdownMutex;
    6364#elif PLATFORM(EFL)
    6465    static bool timerEvent(void*);
  • trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp

    r188311 r188444  
    104104
    105105    private:
    106         MutexLocker m_locker;
     106        LockHolder m_locker;
    107107    };
    108108
    109109    void add(MachineThreads* machineThreads)
    110110    {
    111         MutexLocker managerLock(m_lock);
     111        LockHolder managerLock(m_lock);
    112112        m_set.add(machineThreads);
    113113    }
     
    115115    void remove(MachineThreads* machineThreads)
    116116    {
    117         MutexLocker managerLock(m_lock);
     117        LockHolder managerLock(m_lock);
    118118        auto recordedMachineThreads = m_set.take(machineThreads);
    119119        RELEASE_ASSERT(recordedMachineThreads = machineThreads);
     
    130130    ActiveMachineThreadsManager() { }
    131131   
    132     Mutex m_lock;
     132    Lock m_lock;
    133133    MachineThreadsSet m_set;
    134134
     
    264264    threadSpecificKeyDelete(m_threadSpecific);
    265265
    266     MutexLocker registeredThreadsLock(m_registeredThreadsMutex);
     266    LockHolder registeredThreadsLock(m_registeredThreadsMutex);
    267267    for (Thread* t = m_registeredThreads; t;) {
    268268        Thread* next = t->next;
     
    295295    Thread* thread = Thread::createForCurrentThread();
    296296
    297     MutexLocker lock(m_registeredThreadsMutex);
     297    LockHolder lock(m_registeredThreadsMutex);
    298298
    299299    thread->next = m_registeredThreads;
     
    319319void MachineThreads::removeThreadIfFound(PlatformThread platformThread)
    320320{
    321     MutexLocker lock(m_registeredThreadsMutex);
     321    LockHolder lock(m_registeredThreadsMutex);
    322322    Thread* t = m_registeredThreads;
    323323    if (*t == platformThread) {
     
    567567}
    568568
    569 bool MachineThreads::tryCopyOtherThreadStacks(MutexLocker&, void* buffer, size_t capacity, size_t* size)
     569bool MachineThreads::tryCopyOtherThreadStacks(LockHolder&, void* buffer, size_t capacity, size_t* size)
    570570{
    571571    // Prevent two VMs from suspending each other's threads at the same time,
     
    661661    size_t capacity = 0;
    662662    void* buffer = nullptr;
    663     MutexLocker lock(m_registeredThreadsMutex);
     663    LockHolder lock(m_registeredThreadsMutex);
    664664    while (!tryCopyOtherThreadStacks(lock, buffer, capacity, &size))
    665665        growBuffer(size, &buffer, &capacity);
  • trunk/Source/JavaScriptCore/heap/MachineStackMarker.h

    r188002 r188444  
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 *  Copyright (C) 2001 Peter Kelly ([email protected])
    4  *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2015 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    2424
    2525#include <setjmp.h>
     26#include <wtf/Lock.h>
    2627#include <wtf/Noncopyable.h>
    2728#include <wtf/ThreadSpecific.h>
    28 #include <wtf/ThreadingPrimitives.h>
    2929
    3030namespace JSC {
     
    5353
    5454        void tryCopyOtherThreadStack(Thread*, void*, size_t capacity, size_t*);
    55         bool tryCopyOtherThreadStacks(MutexLocker&, void*, size_t capacity, size_t*);
     55        bool tryCopyOtherThreadStacks(LockHolder&, void*, size_t capacity, size_t*);
    5656
    5757        static void removeThread(void*);
     
    6060        void removeThreadIfFound(PlatformThread);
    6161
    62         Mutex m_registeredThreadsMutex;
     62        Lock m_registeredThreadsMutex;
    6363        Thread* m_registeredThreads;
    6464        WTF::ThreadSpecificKey m_threadSpecific;
  • trunk/Source/JavaScriptCore/heap/SlotVisitor.cpp

    r179348 r188444  
     1/*
     2 * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
     3 *
     4 * Redistribution and use in source and binary forms, with or without
     5 * modification, are permitted provided that the following conditions
     6 * are met:
     7 * 1. Redistributions of source code must retain the above copyright
     8 *    notice, this list of conditions and the following disclaimer.
     9 * 2. Redistributions in binary form must reproduce the above copyright
     10 *    notice, this list of conditions and the following disclaimer in the
     11 *    documentation and/or other materials provided with the distribution.
     12 *
     13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23 * THE POSSIBILITY OF SUCH DAMAGE.
     24 */
     25
    126#include "config.h"
    227#include "SlotVisitor.h"
     
    1338#include "JSString.h"
    1439#include "JSCInlines.h"
     40#include <wtf/Lock.h>
    1541#include <wtf/StackStats.h>
    1642
     
    122148    // If we're contending on the lock, be conservative and assume that another
    123149    // thread is already donating.
    124     std::unique_lock<std::mutex> lock(m_shared.m_markingMutex, std::try_to_lock);
     150    std::unique_lock<Lock> lock(m_shared.m_markingMutex, std::try_to_lock);
    125151    if (!lock.owns_lock())
    126152        return;
     
    130156
    131157    if (m_shared.m_numberOfActiveParallelMarkers < Options::numberOfGCMarkers())
    132         m_shared.m_markingConditionVariable.notify_all();
     158        m_shared.m_markingConditionVariable.notifyAll();
    133159}
    134160
     
    185211#if ENABLE(PARALLEL_GC)
    186212    {
    187         std::lock_guard<std::mutex> lock(m_shared.m_markingMutex);
     213        std::lock_guard<Lock> lock(m_shared.m_markingMutex);
    188214        m_shared.m_numberOfActiveParallelMarkers++;
    189215    }
    190216    while (true) {
    191217        {
    192             std::unique_lock<std::mutex> lock(m_shared.m_markingMutex);
     218            std::unique_lock<Lock> lock(m_shared.m_markingMutex);
    193219            m_shared.m_numberOfActiveParallelMarkers--;
    194220
     
    201227                    if (!m_shared.m_numberOfActiveParallelMarkers && m_shared.m_sharedMarkStack.isEmpty()) {
    202228                        // Let any sleeping slaves know it's time for them to return;
    203                         m_shared.m_markingConditionVariable.notify_all();
     229                        m_shared.m_markingConditionVariable.notifyAll();
    204230                        return;
    205231                    }
     
    217243                // Did we detect termination? If so, let the master know.
    218244                if (!m_shared.m_numberOfActiveParallelMarkers && m_shared.m_sharedMarkStack.isEmpty())
    219                     m_shared.m_markingConditionVariable.notify_all();
     245                    m_shared.m_markingConditionVariable.notifyAll();
    220246
    221247                m_shared.m_markingConditionVariable.wait(lock, [this] { return !m_shared.m_sharedMarkStack.isEmpty() || m_shared.m_parallelMarkersShouldExit; });
     
    241267    ASSERT(!m_opaqueRoots.isEmpty()); // Should only be called when opaque roots are non-empty.
    242268    {
    243         std::lock_guard<std::mutex> lock(m_shared.m_opaqueRootsMutex);
     269        std::lock_guard<Lock> lock(m_shared.m_opaqueRootsMutex);
    244270        for (auto* root : m_opaqueRoots)
    245271            m_shared.m_opaqueRoots.add(root);
  • trunk/Source/JavaScriptCore/heap/SlotVisitorInlines.h

    r188169 r188444  
    189189    if (m_opaqueRoots.contains(root))
    190190        return TrueTriState;
    191     std::lock_guard<std::mutex> lock(m_shared.m_opaqueRootsMutex);
     191    std::lock_guard<Lock> lock(m_shared.m_opaqueRootsMutex);
    192192    if (m_shared.m_opaqueRoots.contains(root))
    193193        return TrueTriState;
  • trunk/Source/JavaScriptCore/inspector/remote/RemoteInspectorDebuggableConnection.h

    r183319 r188444  
    3232#import "RemoteInspectorDebuggable.h"
    3333#import <mutex>
     34#import <wtf/Lock.h>
    3435#import <wtf/RetainPtr.h>
    3536#import <wtf/ThreadSafeRefCounted.h>
     
    9293    virtual bool sendMessageToFrontend(const String&) override;
    9394
    94     std::mutex& queueMutex() { return m_queueMutex; }
     95    Lock& queueMutex() { return m_queueMutex; }
    9596    RemoteInspectorQueue queue() const { return m_queue; }
    9697    void clearQueue() { m_queue.clear(); }
     
    106107    // can be used on multiple threads. So any access to the debuggable
    107108    // itself must take this mutex to ensure m_debuggable is valid.
    108     std::mutex m_debuggableMutex;
     109    Lock m_debuggableMutex;
    109110
    110111    // If a debuggable has a specific run loop it wants to evaluate on
     
    113114    RetainPtr<CFRunLoopSourceRef> m_runLoopSource;
    114115    RemoteInspectorQueue m_queue;
    115     std::mutex m_queueMutex;
     116    Lock m_queueMutex;
    116117
    117118    RemoteInspectorDebuggable* m_debuggable;
  • trunk/Source/JavaScriptCore/inspector/remote/RemoteInspectorDebuggableConnection.mm

    r183319 r188444  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2013, 2015 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4040namespace Inspector {
    4141
    42 static std::mutex* rwiQueueMutex;
     42static StaticLock rwiQueueMutex;
    4343static CFRunLoopSourceRef rwiRunLoopSource;
    4444static RemoteInspectorQueue* rwiQueue;
     
    4747{
    4848    ASSERT(CFRunLoopGetCurrent() == CFRunLoopGetMain());
    49     ASSERT(rwiQueueMutex);
    5049    ASSERT(rwiRunLoopSource);
    5150    ASSERT(rwiQueue);
     
    5352    RemoteInspectorQueue queueCopy;
    5453    {
    55         std::lock_guard<std::mutex> lock(*rwiQueueMutex);
     54        std::lock_guard<StaticLock> lock(rwiQueueMutex);
    5655        queueCopy = *rwiQueue;
    5756        rwiQueue->clear();
     
    6463static void RemoteInspectorQueueTaskOnGlobalQueue(void (^task)())
    6564{
    66     ASSERT(rwiQueueMutex);
    6765    ASSERT(rwiRunLoopSource);
    6866    ASSERT(rwiQueue);
    6967
    7068    {
    71         std::lock_guard<std::mutex> lock(*rwiQueueMutex);
     69        std::lock_guard<StaticLock> lock(rwiQueueMutex);
    7270        rwiQueue->append(RemoteInspectorBlock(task));
    7371    }
     
    8280    dispatch_once(&pred, ^{
    8381        rwiQueue = new RemoteInspectorQueue;
    84         rwiQueueMutex = std::make_unique<std::mutex>().release();
    8582
    8683        CFRunLoopSourceContext runLoopSourceContext = {0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, RemoteInspectorHandleRunSourceGlobal};
     
    9996    RemoteInspectorQueue queueCopy;
    10097    {
    101         std::lock_guard<std::mutex> lock(debuggableConnection->queueMutex());
     98        std::lock_guard<Lock> lock(debuggableConnection->queueMutex());
    10299        queueCopy = debuggableConnection->queue();
    103100        debuggableConnection->clearQueue();
     
    153150bool RemoteInspectorDebuggableConnection::setup(bool isAutomaticInspection, bool automaticallyPause)
    154151{
    155     std::lock_guard<std::mutex> lock(m_debuggableMutex);
     152    std::lock_guard<Lock> lock(m_debuggableMutex);
    156153
    157154    if (!m_debuggable)
     
    161158    dispatchAsyncOnDebuggable(^{
    162159        {
    163             std::lock_guard<std::mutex> lock(m_debuggableMutex);
     160            std::lock_guard<Lock> lock(m_debuggableMutex);
    164161            if (!m_debuggable || !m_debuggable->remoteDebuggingAllowed() || m_debuggable->hasLocalDebugger()) {
    165162                RemoteInspector::singleton().setupFailed(identifier());
     
    181178void RemoteInspectorDebuggableConnection::closeFromDebuggable()
    182179{
    183     std::lock_guard<std::mutex> lock(m_debuggableMutex);
     180    std::lock_guard<Lock> lock(m_debuggableMutex);
    184181
    185182    m_debuggable = nullptr;
     
    191188    dispatchAsyncOnDebuggable(^{
    192189        {
    193             std::lock_guard<std::mutex> lock(m_debuggableMutex);
     190            std::lock_guard<Lock> lock(m_debuggableMutex);
    194191
    195192            if (m_debuggable) {
     
    211208            RemoteInspectorDebuggable* debuggable = nullptr;
    212209            {
    213                 std::lock_guard<std::mutex> lock(m_debuggableMutex);
     210                std::lock_guard<Lock> lock(m_debuggableMutex);
    214211                if (!m_debuggable)
    215212                    return;
     
    264261
    265262    {
    266         std::lock_guard<std::mutex> lock(m_queueMutex);
     263        std::lock_guard<Lock> lock(m_queueMutex);
    267264        m_queue.append(RemoteInspectorBlock(block));
    268265    }
  • trunk/Source/JavaScriptCore/interpreter/JSStack.cpp

    r188002 r188444  
    11/*
    2  * Copyright (C) 2008, 2013, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2013, 2014, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434#include "JSCInlines.h"
    3535#include "Options.h"
     36#include <wtf/Lock.h>
    3637
    3738namespace JSC {
     
    4041static size_t committedBytesCount = 0;
    4142
    42 static Mutex& stackStatisticsMutex()
    43 {
    44     DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
    45     return staticMutex;
    46 }   
     43static StaticLock stackStatisticsMutex;
    4744#endif // !ENABLE(JIT)
    4845
     
    140137}
    141138
    142 void JSStack::initializeThreading()
    143 {
    144     stackStatisticsMutex();
    145 }
    146 
    147139void JSStack::addToCommittedByteCount(long byteCount)
    148140{
    149     MutexLocker locker(stackStatisticsMutex());
     141    LockHolder locker(stackStatisticsMutex);
    150142    ASSERT(static_cast<long>(committedBytesCount) + byteCount > -1);
    151143    committedBytesCount += byteCount;
     
    177169{
    178170#if !ENABLE(JIT)
    179     MutexLocker locker(stackStatisticsMutex());
     171    LockHolder locker(stackStatisticsMutex);
    180172    return committedBytesCount;
    181173#else
  • trunk/Source/JavaScriptCore/interpreter/JSStack.h

    r178856 r188444  
    8383        void gatherConservativeRoots(ConservativeRoots&, JITStubRoutineSet&, CodeBlockSet&) { }
    8484        void sanitizeStack() { }
    85         static void initializeThreading() { }
    8685#else
    8786        ~JSStack();
     
    9796
    9897        size_t size() const { return highAddress() - lowAddress(); }
    99 
    100         static void initializeThreading();
    10198
    10299        void setReservedZoneSize(size_t);
  • trunk/Source/JavaScriptCore/jit/ExecutableAllocator.cpp

    r185532 r188444  
    3232#include "CodeProfiling.h"
    3333#include <wtf/HashSet.h>
     34#include <wtf/Lock.h>
    3435#include <wtf/MetaAllocator.h>
    3536#include <wtf/NeverDestroyed.h>
    3637#include <wtf/PageReservation.h>
    37 #include <wtf/ThreadingPrimitives.h>
    3838#include <wtf/VMTags.h>
    3939#endif
     
    5757        : MetaAllocator(jitAllocationGranule)
    5858    {
    59         std::lock_guard<std::mutex> lock(allocatorsMutex());
     59        std::lock_guard<StaticLock> lock(allocatorsMutex());
    6060        allocators().add(this);
    6161        // Don't preallocate any memory here.
     
    6565    {
    6666        {
    67             std::lock_guard<std::mutex> lock(allocatorsMutex());
     67            std::lock_guard<StaticLock> lock(allocatorsMutex());
    6868            allocators().remove(this);
    6969        }
     
    7575    {
    7676        size_t total = 0;
    77         std::lock_guard<std::mutex> lock(allocatorsMutex());
     77        std::lock_guard<StaticLock> lock(allocatorsMutex());
    7878        for (HashSet<DemandExecutableAllocator*>::const_iterator allocator = allocators().begin(); allocator != allocators().end(); ++allocator)
    7979            total += (*allocator)->bytesAllocated();
     
    8484    {
    8585        size_t total = 0;
    86         std::lock_guard<std::mutex> lock(allocatorsMutex());
     86        std::lock_guard<StaticLock> lock(allocatorsMutex());
    8787        for (HashSet<DemandExecutableAllocator*>::const_iterator allocator = allocators().begin(); allocator != allocators().end(); ++allocator)
    8888            total += (*allocator)->bytesCommitted();
     
    9393    static void dumpProfileFromAllAllocators()
    9494    {
    95         std::lock_guard<std::mutex> lock(allocatorsMutex());
     95        std::lock_guard<StaticLock> lock(allocatorsMutex());
    9696        for (HashSet<DemandExecutableAllocator*>::const_iterator allocator = allocators().begin(); allocator != allocators().end(); ++allocator)
    9797            (*allocator)->dumpProfile();
     
    139139    }
    140140
    141     static std::mutex& allocatorsMutex()
    142     {
    143         static NeverDestroyed<std::mutex> mutex;
     141    static StaticLock& allocatorsMutex()
     142    {
     143        static StaticLock mutex;
    144144
    145145        return mutex;
  • trunk/Source/JavaScriptCore/jit/JITThunks.cpp

    r181250 r188444  
    11/*
    2  * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2013, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6767MacroAssemblerCodeRef JITThunks::ctiStub(VM* vm, ThunkGenerator generator)
    6868{
    69     Locker locker(m_lock);
     69    LockHolder locker(m_lock);
    7070    CTIStubMap::AddResult entry = m_ctiStubMap.add(generator, MacroAssemblerCodeRef());
    7171    if (entry.isNewEntry) {
  • trunk/Source/JavaScriptCore/jit/JITThunks.h

    r188002 r188444  
    6464
    6565private:
    66     // Main thread can hold this lock for a while, so use an adaptive mutex.
    67     typedef Mutex Lock;
    68     typedef MutexLocker Locker;
    69 
    7066    void finalize(Handle<Unknown>, void* context) override;
    7167   
  • trunk/Source/JavaScriptCore/profiler/ProfilerDatabase.cpp

    r188169 r188444  
    5858Bytecodes* Database::ensureBytecodesFor(CodeBlock* codeBlock)
    5959{
    60     Locker locker(m_lock);
     60    LockHolder locker(m_lock);
    6161   
    6262    codeBlock = codeBlock->baselineVersion();
     
    7676void Database::notifyDestruction(CodeBlock* codeBlock)
    7777{
    78     Locker locker(m_lock);
     78    LockHolder locker(m_lock);
    7979   
    8080    m_bytecodesMap.remove(codeBlock);
  • trunk/Source/JavaScriptCore/profiler/ProfilerDatabase.h

    r188002 r188444  
    3333#include <wtf/FastMalloc.h>
    3434#include <wtf/HashMap.h>
     35#include <wtf/Lock.h>
    3536#include <wtf/Noncopyable.h>
    3637#include <wtf/PassRefPtr.h>
     
    7172   
    7273private:
    73     // Use a full-blown adaptive mutex because:
    74     // - There is only one ProfilerDatabase per VM. The size overhead of the system's
    75     //   mutex is negligible if you only have one of them.
    76     // - It's locked infrequently - once per bytecode generation, compilation, and
    77     //   code block collection - so the fact that the fast path still requires a
    78     //   function call is neglible.
    79     // - It tends to be held for a while. Currently, we hold it while generating
    80     //   Profiler::Bytecodes for a CodeBlock. That's uncommon and shouldn't affect
    81     //   performance, but if we did have contention, we would want a sensible,
    82     //   power-aware backoff. An adaptive mutex will do this as a matter of course,
    83     //   but a spinlock won't.
    84     typedef Mutex Lock;
    85     typedef MutexLocker Locker;
    86    
    87 
    8874    void addDatabaseToAtExit();
    8975    void removeDatabaseFromAtExit();
  • trunk/Source/JavaScriptCore/runtime/InitializeThreading.cpp

    r170147 r188444  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5757        WTF::double_conversion::initialize();
    5858        WTF::initializeThreading();
    59         GlobalJSLock::initialize();
    6059        Options::initialize();
    6160        if (Options::recordGCPauseTimes())
     
    6766        ExecutableAllocator::initializeAllocator();
    6867#endif
    69         JSStack::initializeThreading();
    7068        LLInt::initialize();
    7169#ifndef NDEBUG
  • trunk/Source/JavaScriptCore/runtime/JSLock.cpp

    r187026 r188444  
    3131namespace JSC {
    3232
    33 std::mutex* GlobalJSLock::s_sharedInstanceMutex;
     33StaticLock GlobalJSLock::s_sharedInstanceMutex;
    3434
    3535GlobalJSLock::GlobalJSLock()
    3636{
    37     s_sharedInstanceMutex->lock();
     37    s_sharedInstanceMutex.lock();
    3838}
    3939
    4040GlobalJSLock::~GlobalJSLock()
    4141{
    42     s_sharedInstanceMutex->unlock();
    43 }
    44 
    45 void GlobalJSLock::initialize()
    46 {
    47     s_sharedInstanceMutex = new std::mutex();
     42    s_sharedInstanceMutex.unlock();
    4843}
    4944
  • trunk/Source/JavaScriptCore/runtime/JSLock.h

    r187026 r188444  
    2525#include <thread>
    2626#include <wtf/Assertions.h>
     27#include <wtf/Lock.h>
    2728#include <wtf/Noncopyable.h>
    2829#include <wtf/RefPtr.h>
     
    6162    JS_EXPORT_PRIVATE GlobalJSLock();
    6263    JS_EXPORT_PRIVATE ~GlobalJSLock();
    63 
    64     static void initialize();
    6564private:
    66     static std::mutex* s_sharedInstanceMutex;
     65    static StaticLock s_sharedInstanceMutex;
    6766};
    6867
     
    134133    void grabAllLocks(DropAllLocks*, unsigned lockCount);
    135134
    136     std::mutex m_lock;
     135    Lock m_lock;
    137136    std::thread::id m_ownerThreadID;
    138137    intptr_t m_lockCount;
  • trunk/Source/WTF/ChangeLog

    r188436 r188444  
     12015-08-13  Filip Pizlo  <[email protected]>
     2
     3        Use WTF::Lock and WTF::Condition instead of WTF::Mutex, WTF::ThreadCondition, std::mutex, and std::condition_variable
     4        https://bugs.webkit.org/show_bug.cgi?id=147999
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * wtf/Condition.h: "using WTF::Condition".
     9        * wtf/Lock.h:
     10        (WTF::LockBase::lock):
     11        (WTF::LockBase::tryLock): Add tryLock() because it turns out that we use it sometimes.
     12        (WTF::LockBase::try_lock): unique_lock needs this.
     13        (WTF::LockBase::unlock):
     14
    1152015-08-13  Commit Queue  <[email protected]>
    216
  • trunk/Source/WTF/wtf/Condition.h

    r188400 r188444  
    110110} // namespace WTF
    111111
     112using WTF::Condition;
     113
    112114#endif // WTF_Condition_h
    113115
  • trunk/Source/WTF/wtf/Lock.h

    r188374 r188444  
    5555
    5656        lockSlow();
     57    }
     58
     59    bool tryLock()
     60    {
     61        for (;;) {
     62            uint8_t currentByteValue = m_byte.load();
     63            if (currentByteValue & isHeldBit)
     64                return false;
     65            if (m_byte.compareExchangeWeak(currentByteValue, currentByteValue | isHeldBit))
     66                return true;
     67        }
     68    }
     69
     70    // Need this version for std::unique_lock.
     71    bool try_lock()
     72    {
     73        return tryLock();
    5774    }
    5875
Note: See TracChangeset for help on using the changeset viewer.