Changeset 245258 in webkit


Ignore:
Timestamp:
May 13, 2019 3:32:34 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[WTF] Simplify GCThread and CompilationThread flags by adding them to WTF::Thread
https://bugs.webkit.org/show_bug.cgi?id=197146

Reviewed by Saam Barati.

Source/JavaScriptCore:

Rename Heap::Thread to Heap::HeapThread to remove conflict between WTF::Thread.

  • heap/AlignedMemoryAllocator.cpp:

(JSC::AlignedMemoryAllocator::registerDirectory):

  • heap/Heap.cpp:

(JSC::Heap::HeapThread::HeapThread):
(JSC::Heap::Heap):
(JSC::Heap::runCurrentPhase):
(JSC::Heap::runBeginPhase):
(JSC::Heap::resumeThePeriphery):
(JSC::Heap::requestCollection):
(JSC::Heap::isCurrentThreadBusy):
(JSC::Heap::notifyIsSafeToCollect):
(JSC::Heap::Thread::Thread): Deleted.

  • heap/Heap.h:
  • heap/HeapInlines.h:

(JSC::Heap::incrementDeferralDepth):
(JSC::Heap::decrementDeferralDepth):
(JSC::Heap::decrementDeferralDepthAndGCIfNeeded):

  • heap/MarkedSpace.cpp:

(JSC::MarkedSpace::prepareForAllocation):

Source/WebCore:

  • Modules/indexeddb/IDBDatabase.cpp:

(WebCore::IDBDatabase::hasPendingActivity const):

  • Modules/indexeddb/IDBRequest.cpp:

(WebCore::IDBRequest::hasPendingActivity const):

  • Modules/indexeddb/IDBTransaction.cpp:

(WebCore::IDBTransaction::hasPendingActivity const):

Source/WTF:

Since GCThread and CompilationThread flags exist in WTF, we put these flags into WTF::Thread directly instead of holding them in ThreadSpecific<>.
And this patch removes dependency from Threading.h to ThreadSpecific.h. ThreadSpecific.h's OS threading primitives are moved to ThreadingPrimitives.h,
and Threading.h relies on it instead.

  • wtf/CompilationThread.cpp:

(WTF::isCompilationThread):
(WTF::initializeCompilationThreads): Deleted.
(WTF::exchangeIsCompilationThread): Deleted.

  • wtf/CompilationThread.h:

(WTF::CompilationScope::CompilationScope):
(WTF::CompilationScope::~CompilationScope):
(WTF::CompilationScope::leaveEarly):

  • wtf/MainThread.cpp:

(WTF::initializeMainThread):
(WTF::initializeMainThreadToProcessMainThread):
(WTF::isMainThreadOrGCThread):
(WTF::initializeGCThreads): Deleted.
(WTF::registerGCThread): Deleted.
(WTF::mayBeGCThread): Deleted.

  • wtf/MainThread.h:
  • wtf/ThreadSpecific.h:

(WTF::canBeGCThread>::ThreadSpecific):
(WTF::canBeGCThread>::set):
(WTF::threadSpecificKeyCreate): Deleted.
(WTF::threadSpecificKeyDelete): Deleted.
(WTF::threadSpecificSet): Deleted.
(WTF::threadSpecificGet): Deleted.

  • wtf/Threading.cpp:

(WTF::Thread::exchangeIsCompilationThread):
(WTF::Thread::registerGCThread):
(WTF::Thread::mayBeGCThread):

  • wtf/Threading.h:

(WTF::Thread::isCompilationThread const):
(WTF::Thread::gcThreadType const):
(WTF::Thread::joinableState const):
(WTF::Thread::hasExited const):
(WTF::Thread::Thread):
(WTF::Thread::joinableState): Deleted.
(WTF::Thread::hasExited): Deleted.

  • wtf/ThreadingPrimitives.h:

(WTF::threadSpecificKeyCreate):
(WTF::threadSpecificKeyDelete):
(WTF::threadSpecificSet):
(WTF::threadSpecificGet):

  • wtf/win/ThreadSpecificWin.cpp:

(WTF::flsKeys):

Location:
trunk/Source
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r245251 r245258  
     12019-05-13  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [WTF] Simplify GCThread and CompilationThread flags by adding them to WTF::Thread
     4        https://bugs.webkit.org/show_bug.cgi?id=197146
     5
     6        Reviewed by Saam Barati.
     7
     8        Rename Heap::Thread to Heap::HeapThread to remove conflict between WTF::Thread.
     9
     10        * heap/AlignedMemoryAllocator.cpp:
     11        (JSC::AlignedMemoryAllocator::registerDirectory):
     12        * heap/Heap.cpp:
     13        (JSC::Heap::HeapThread::HeapThread):
     14        (JSC::Heap::Heap):
     15        (JSC::Heap::runCurrentPhase):
     16        (JSC::Heap::runBeginPhase):
     17        (JSC::Heap::resumeThePeriphery):
     18        (JSC::Heap::requestCollection):
     19        (JSC::Heap::isCurrentThreadBusy):
     20        (JSC::Heap::notifyIsSafeToCollect):
     21        (JSC::Heap::Thread::Thread): Deleted.
     22        * heap/Heap.h:
     23        * heap/HeapInlines.h:
     24        (JSC::Heap::incrementDeferralDepth):
     25        (JSC::Heap::decrementDeferralDepth):
     26        (JSC::Heap::decrementDeferralDepthAndGCIfNeeded):
     27        * heap/MarkedSpace.cpp:
     28        (JSC::MarkedSpace::prepareForAllocation):
     29
    1302019-05-13  Saam Barati  <sbarati@apple.com>
    231
  • trunk/Source/JavaScriptCore/heap/AlignedMemoryAllocator.cpp

    r240965 r245258  
    4646   
    4747    if (m_directories.isEmpty()) {
    48         ASSERT(!mayBeGCThread() || directory->heap()->worldIsStopped());
     48        ASSERT(!Thread::mayBeGCThread() || directory->heap()->worldIsStopped());
    4949        for (Subspace* subspace = m_subspaces.first(); subspace; subspace = subspace->nextSubspaceInAlignedMemoryAllocator())
    5050            subspace->didCreateFirstDirectory(directory);
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r244745 r245258  
    149149bool isValidThreadState(VM* vm)
    150150{
    151     if (vm->atomicStringTable() != WTF::Thread::current().atomicStringTable())
     151    if (vm->atomicStringTable() != Thread::current().atomicStringTable())
    152152        return false;
    153153
     
    232232} // anonymous namespace
    233233
    234 class Heap::Thread : public AutomaticThread {
     234class Heap::HeapThread : public AutomaticThread {
    235235public:
    236     Thread(const AbstractLocker& locker, Heap& heap)
     236    HeapThread(const AbstractLocker& locker, Heap& heap)
    237237        : AutomaticThread(locker, heap.m_threadLock, heap.m_threadCondition.copyRef())
    238238        , m_heap(heap)
     
    265265    void threadDidStart() override
    266266    {
    267         WTF::registerGCThread(GCThreadType::Main);
     267        Thread::registerGCThread(GCThreadType::Main);
    268268    }
    269269
     
    324324
    325325    LockHolder locker(*m_threadLock);
    326     m_thread = adoptRef(new Thread(locker, *this));
     326    m_thread = adoptRef(new HeapThread(locker, *this));
    327327}
    328328
     
    11701170    checkConn(conn);
    11711171    m_currentThreadState = currentThreadState;
    1172     m_currentThread = &WTF::Thread::current();
     1172    m_currentThread = &Thread::current();
    11731173   
    11741174    if (conn == GCConductor::Mutator)
     
    12991299            }
    13001300
    1301             WTF::registerGCThread(GCThreadType::Helper);
     1301            Thread::registerGCThread(GCThreadType::Helper);
    13021302
    13031303            {
     
    16961696            }
    16971697        }
    1698         WTF::Thread::yield();
     1698        Thread::yield();
    16991699    }
    17001700   
     
    21062106   
    21072107    ASSERT(vm()->currentThreadIsHoldingAPILock());
    2108     RELEASE_ASSERT(vm()->atomicStringTable() == WTF::Thread::current().atomicStringTable());
     2108    RELEASE_ASSERT(vm()->atomicStringTable() == Thread::current().atomicStringTable());
    21092109   
    21102110    LockHolder locker(*m_threadLock);
     
    25492549bool Heap::isCurrentThreadBusy()
    25502550{
    2551     return mayBeGCThread() || mutatorState() != MutatorState::Running;
     2551    return Thread::mayBeGCThread() || mutatorState() != MutatorState::Running;
    25522552}
    25532553
     
    28652865   
    28662866    if (Options::collectContinuously()) {
    2867         m_collectContinuouslyThread = WTF::Thread::create(
     2867        m_collectContinuouslyThread = Thread::create(
    28682868            "JSC DEBUG Continuous GC",
    28692869            [this] () {
  • trunk/Source/JavaScriptCore/heap/Heap.h

    r243467 r245258  
    427427    friend class WeakSet;
    428428
    429     class Thread;
    430     friend class Thread;
     429    class HeapThread;
     430    friend class HeapThread;
    431431
    432432    static const size_t minExtraMemory = 256;
     
    728728    RefPtr<AutomaticThread> m_thread;
    729729
    730     RefPtr<WTF::Thread> m_collectContinuouslyThread { nullptr };
     730    RefPtr<Thread> m_collectContinuouslyThread { nullptr };
    731731   
    732732    MonotonicTime m_lastGCStartTime;
     
    738738   
    739739    CurrentThreadState* m_currentThreadState { nullptr };
    740     WTF::Thread* m_currentThread { nullptr }; // It's OK if this becomes a dangling pointer.
     740    Thread* m_currentThread { nullptr }; // It's OK if this becomes a dangling pointer.
    741741
    742742#if PLATFORM(IOS_FAMILY)
  • trunk/Source/JavaScriptCore/heap/HeapInlines.h

    r244088 r245258  
    174174inline void Heap::incrementDeferralDepth()
    175175{
    176     ASSERT(!mayBeGCThread() || m_worldIsStopped);
     176    ASSERT(!Thread::mayBeGCThread() || m_worldIsStopped);
    177177    m_deferralDepth++;
    178178}
     
    180180inline void Heap::decrementDeferralDepth()
    181181{
    182     ASSERT(!mayBeGCThread() || m_worldIsStopped);
     182    ASSERT(!Thread::mayBeGCThread() || m_worldIsStopped);
    183183    m_deferralDepth--;
    184184}
     
    186186inline void Heap::decrementDeferralDepthAndGCIfNeeded()
    187187{
    188     ASSERT(!mayBeGCThread() || m_worldIsStopped);
     188    ASSERT(!Thread::mayBeGCThread() || m_worldIsStopped);
    189189    m_deferralDepth--;
    190190   
  • trunk/Source/JavaScriptCore/heap/MarkedSpace.cpp

    r243688 r245258  
    260260void MarkedSpace::prepareForAllocation()
    261261{
    262     ASSERT(!mayBeGCThread() || m_heap->worldIsStopped());
     262    ASSERT(!Thread::mayBeGCThread() || m_heap->worldIsStopped());
    263263    for (Subspace* subspace : m_subspaces)
    264264        subspace->prepareForAllocation();
  • trunk/Source/WTF/ChangeLog

    r245254 r245258  
     12019-05-13  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [WTF] Simplify GCThread and CompilationThread flags by adding them to WTF::Thread
     4        https://bugs.webkit.org/show_bug.cgi?id=197146
     5
     6        Reviewed by Saam Barati.
     7
     8        Since GCThread and CompilationThread flags exist in WTF, we put these flags into WTF::Thread directly instead of holding them in ThreadSpecific<>.
     9        And this patch removes dependency from Threading.h to ThreadSpecific.h. ThreadSpecific.h's OS threading primitives are moved to ThreadingPrimitives.h,
     10        and Threading.h relies on it instead.
     11
     12        * wtf/CompilationThread.cpp:
     13        (WTF::isCompilationThread):
     14        (WTF::initializeCompilationThreads): Deleted.
     15        (WTF::exchangeIsCompilationThread): Deleted.
     16        * wtf/CompilationThread.h:
     17        (WTF::CompilationScope::CompilationScope):
     18        (WTF::CompilationScope::~CompilationScope):
     19        (WTF::CompilationScope::leaveEarly):
     20        * wtf/MainThread.cpp:
     21        (WTF::initializeMainThread):
     22        (WTF::initializeMainThreadToProcessMainThread):
     23        (WTF::isMainThreadOrGCThread):
     24        (WTF::initializeGCThreads): Deleted.
     25        (WTF::registerGCThread): Deleted.
     26        (WTF::mayBeGCThread): Deleted.
     27        * wtf/MainThread.h:
     28        * wtf/ThreadSpecific.h:
     29        (WTF::canBeGCThread>::ThreadSpecific):
     30        (WTF::canBeGCThread>::set):
     31        (WTF::threadSpecificKeyCreate): Deleted.
     32        (WTF::threadSpecificKeyDelete): Deleted.
     33        (WTF::threadSpecificSet): Deleted.
     34        (WTF::threadSpecificGet): Deleted.
     35        * wtf/Threading.cpp:
     36        (WTF::Thread::exchangeIsCompilationThread):
     37        (WTF::Thread::registerGCThread):
     38        (WTF::Thread::mayBeGCThread):
     39        * wtf/Threading.h:
     40        (WTF::Thread::isCompilationThread const):
     41        (WTF::Thread::gcThreadType const):
     42        (WTF::Thread::joinableState const):
     43        (WTF::Thread::hasExited const):
     44        (WTF::Thread::Thread):
     45        (WTF::Thread::joinableState): Deleted.
     46        (WTF::Thread::hasExited): Deleted.
     47        * wtf/ThreadingPrimitives.h:
     48        (WTF::threadSpecificKeyCreate):
     49        (WTF::threadSpecificKeyDelete):
     50        (WTF::threadSpecificSet):
     51        (WTF::threadSpecificGet):
     52        * wtf/win/ThreadSpecificWin.cpp:
     53        (WTF::flsKeys):
     54
    1552019-05-13  Yusuke Suzuki  <ysuzuki@apple.com>
    256
  • trunk/Source/WTF/wtf/CompilationThread.cpp

    r237099 r245258  
    2727#include <wtf/CompilationThread.h>
    2828
    29 #include <mutex>
    3029#include <wtf/StdLibExtras.h>
    31 #include <wtf/ThreadSpecific.h>
    3230#include <wtf/Threading.h>
    3331
    3432namespace WTF {
    3533
    36 static ThreadSpecific<bool, CanBeGCThread::True>* s_isCompilationThread;
    37 
    38 static void initializeCompilationThreads()
    39 {
    40     static std::once_flag initializeCompilationThreadsOnceFlag;
    41     std::call_once(initializeCompilationThreadsOnceFlag, []{
    42         s_isCompilationThread = new ThreadSpecific<bool, CanBeGCThread::True>();
    43     });
    44 }
    45 
    4634bool isCompilationThread()
    4735{
    48     if (!s_isCompilationThread)
    49         return false;
    50     if (!s_isCompilationThread->isSet())
    51         return false;
    52     return **s_isCompilationThread;
    53 }
    54 
    55 bool exchangeIsCompilationThread(bool newValue)
    56 {
    57     initializeCompilationThreads();
    58     bool oldValue = isCompilationThread();
    59     **s_isCompilationThread = newValue;
    60     return oldValue;
     36    return Thread::current().isCompilationThread();
    6137}
    6238
  • trunk/Source/WTF/wtf/CompilationThread.h

    r237099 r245258  
    2626#pragma once
    2727
     28#include <wtf/Threading.h>
     29
    2830namespace WTF {
    29 
    30 WTF_EXPORT_PRIVATE bool exchangeIsCompilationThread(bool newValue);
    3131
    3232class CompilationScope {
    3333public:
    3434    CompilationScope()
    35         : m_oldValue(exchangeIsCompilationThread(true))
     35        : m_oldValue(Thread::exchangeIsCompilationThread(true))
    3636    {
    3737    }
     
    3939    ~CompilationScope()
    4040    {
    41         exchangeIsCompilationThread(m_oldValue);
     41        Thread::exchangeIsCompilationThread(m_oldValue);
    4242    }
    4343   
    4444    void leaveEarly()
    4545    {
    46         exchangeIsCompilationThread(m_oldValue);
     46        Thread::exchangeIsCompilationThread(m_oldValue);
    4747    }
    4848private:
     
    5353
    5454using WTF::CompilationScope;
    55 using WTF::exchangeIsCompilationThread;
  • trunk/Source/WTF/wtf/MainThread.cpp

    r239427 r245258  
    5858        initializeThreading();
    5959        initializeMainThreadPlatform();
    60         initializeGCThreads();
    6160    });
    6261}
     
    6968        initializeThreading();
    7069        initializeMainThreadToProcessMainThreadPlatform();
    71         initializeGCThreads();
    7270    });
    7371}
     
    158156}
    159157
    160 static ThreadSpecific<Optional<GCThreadType>, CanBeGCThread::True>* isGCThread;
    161 
    162 void initializeGCThreads()
    163 {
    164     static std::once_flag flag;
    165     std::call_once(
    166         flag,
    167         [] {
    168             isGCThread = new ThreadSpecific<Optional<GCThreadType>, CanBeGCThread::True>();
    169         });
    170 }
    171 
    172 void registerGCThread(GCThreadType type)
    173 {
    174     if (!isGCThread) {
    175         // This happens if we're running in a process that doesn't care about
    176         // MainThread.
    177         return;
    178     }
    179 
    180     **isGCThread = type;
    181 }
    182 
    183158bool isMainThreadOrGCThread()
    184159{
    185     if (mayBeGCThread())
     160    if (Thread::mayBeGCThread())
    186161        return true;
    187162
    188163    return isMainThread();
    189 }
    190 
    191 Optional<GCThreadType> mayBeGCThread()
    192 {
    193     if (!isGCThread)
    194         return WTF::nullopt;
    195     if (!isGCThread->isSet())
    196         return WTF::nullopt;
    197     return **isGCThread;
    198164}
    199165
  • trunk/Source/WTF/wtf/MainThread.h

    r243795 r245258  
    6969#endif // USE(WEB_THREAD)
    7070
    71 WTF_EXPORT_PRIVATE void initializeGCThreads();
    72 
    73 enum class GCThreadType {
    74     Main,
    75     Helper
    76 };
    77 
    78 void printInternal(PrintStream&, GCThreadType);
    79 
    80 WTF_EXPORT_PRIVATE void registerGCThread(GCThreadType);
    81 WTF_EXPORT_PRIVATE Optional<GCThreadType> mayBeGCThread();
    8271WTF_EXPORT_PRIVATE bool isMainThreadOrGCThread();
    8372
     
    9988} // namespace WTF
    10089
    101 using WTF::GCThreadType;
    10290using WTF::callOnMainThread;
    10391using WTF::callOnMainThreadAndWait;
     
    10795using WTF::isUIThread;
    10896using WTF::isWebThread;
    109 using WTF::mayBeGCThread;
    11097using WTF::setMainThreadCallbacksPaused;
    11198#if PLATFORM(COCOA)
  • trunk/Source/WTF/wtf/ThreadSpecific.h

    r237099 r245258  
    4545#include <wtf/Noncopyable.h>
    4646#include <wtf/StdLibExtras.h>
    47 
    48 #if USE(PTHREADS)
    49 #include <pthread.h>
    50 
    51 #if OS(HURD)
    52 // PTHREAD_KEYS_MAX is not defined in bionic nor in Hurd, so explicitly define it here.
    53 #define PTHREAD_KEYS_MAX 1024
    54 #else
    55 #include <limits.h>
    56 #endif
    57 
    58 #elif OS(WINDOWS)
    59 #include <windows.h>
    60 #endif
     47#include <wtf/Threading.h>
    6148
    6249namespace WTF {
    63 
    64 #if OS(WINDOWS) && CPU(X86)
    65 #define THREAD_SPECIFIC_CALL __stdcall
    66 #else
    67 #define THREAD_SPECIFIC_CALL
    68 #endif
    6950
    7051enum class CanBeGCThread {
     
    130111#if USE(PTHREADS)
    131112
    132 typedef pthread_key_t ThreadSpecificKey;
    133 
    134 static const constexpr ThreadSpecificKey InvalidThreadSpecificKey = PTHREAD_KEYS_MAX;
    135 
    136 inline void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
    137 {
    138     int error = pthread_key_create(key, destructor);
    139     if (error)
    140         CRASH();
    141 }
    142 
    143 inline void threadSpecificKeyDelete(ThreadSpecificKey key)
    144 {
    145     int error = pthread_key_delete(key);
    146     if (error)
    147         CRASH();
    148 }
    149 
    150 inline void threadSpecificSet(ThreadSpecificKey key, void* value)
    151 {
    152     pthread_setspecific(key, value);
    153 }
    154 
    155 inline void* threadSpecificGet(ThreadSpecificKey key)
    156 {
    157     return pthread_getspecific(key);
    158 }
    159 
    160113template<typename T, CanBeGCThread canBeGCThread>
    161114inline ThreadSpecific<T, canBeGCThread>::ThreadSpecific()
     
    186139// 1) Once the instance of ThreadSpecific<> is created, it will not be destructed until the program dies.
    187140// 2) We do not need to hold many instances of ThreadSpecific<> data. This fixed number should be far enough.
    188 const int kMaxFlsKeySize = 128;
     141static constexpr int maxFlsKeySize = 128;
    189142
    190143WTF_EXPORT_PRIVATE long& flsKeyCount();
    191144WTF_EXPORT_PRIVATE DWORD* flsKeys();
    192 
    193 typedef DWORD ThreadSpecificKey;
    194 
    195 static const constexpr ThreadSpecificKey InvalidThreadSpecificKey = FLS_OUT_OF_INDEXES;
    196 
    197 inline void threadSpecificKeyCreate(ThreadSpecificKey* key, void (THREAD_SPECIFIC_CALL *destructor)(void *))
    198 {
    199     DWORD flsKey = FlsAlloc(destructor);
    200     if (flsKey == FLS_OUT_OF_INDEXES)
    201         CRASH();
    202 
    203     *key = flsKey;
    204 }
    205 
    206 inline void threadSpecificKeyDelete(ThreadSpecificKey key)
    207 {
    208     FlsFree(key);
    209 }
    210 
    211 inline void threadSpecificSet(ThreadSpecificKey key, void* data)
    212 {
    213     FlsSetValue(key, data);
    214 }
    215 
    216 inline void* threadSpecificGet(ThreadSpecificKey key)
    217 {
    218     return FlsGetValue(key);
    219 }
    220145
    221146template<typename T, CanBeGCThread canBeGCThread>
     
    228153
    229154    m_index = InterlockedIncrement(&flsKeyCount()) - 1;
    230     if (m_index >= kMaxFlsKeySize)
     155    if (m_index >= maxFlsKeySize)
    231156        CRASH();
    232157    flsKeys()[m_index] = flsKey;
     
    275200inline T* ThreadSpecific<T, canBeGCThread>::set()
    276201{
    277     RELEASE_ASSERT(canBeGCThread == CanBeGCThread::True || !mayBeGCThread());
     202    RELEASE_ASSERT(canBeGCThread == CanBeGCThread::True || !Thread::mayBeGCThread());
    278203    ASSERT(!get());
    279204    Data* data = new Data(this); // Data will set itself into TLS.
  • trunk/Source/WTF/wtf/Threading.cpp

    r242812 r245258  
    260260}
    261261
     262bool Thread::exchangeIsCompilationThread(bool newValue)
     263{
     264    auto& thread = Thread::current();
     265    bool oldValue = thread.m_isCompilationThread;
     266    thread.m_isCompilationThread = newValue;
     267    return oldValue;
     268}
     269
     270void Thread::registerGCThread(GCThreadType gcThreadType)
     271{
     272    Thread::current().m_gcThreadType = static_cast<unsigned>(gcThreadType);
     273}
     274
     275bool Thread::mayBeGCThread()
     276{
     277    return Thread::current().gcThreadType() != GCThreadType::None;
     278}
     279
    262280void Thread::setCurrentThreadIsUserInteractive(int relativePriority)
    263281{
  • trunk/Source/WTF/wtf/Threading.h

    r241739 r245258  
    4444#include <wtf/StackStats.h>
    4545#include <wtf/ThreadSafeRefCounted.h>
    46 #include <wtf/ThreadSpecific.h>
    4746#include <wtf/Vector.h>
    4847#include <wtf/WordLock.h>
     
    8180WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier);
    8281#endif
     82
     83enum class GCThreadType : uint8_t {
     84    None = 0,
     85    Main,
     86    Helper,
     87};
    8388
    8489class Thread : public ThreadSafeRefCounted<Thread> {
     
    151156    WTF_EXPORT_PRIVATE static void yield();
    152157
     158    WTF_EXPORT_PRIVATE static bool exchangeIsCompilationThread(bool newValue);
     159    WTF_EXPORT_PRIVATE static void registerGCThread(GCThreadType);
     160    WTF_EXPORT_PRIVATE static bool mayBeGCThread();
     161
    153162    WTF_EXPORT_PRIVATE void dump(PrintStream& out) const;
    154163
     
    203212#endif
    204213
     214    bool isCompilationThread() const { return m_isCompilationThread; }
     215    GCThreadType gcThreadType() const { return static_cast<GCThreadType>(m_gcThreadType); }
     216
    205217    struct NewThreadContext;
    206218    static void entryPoint(NewThreadContext*);
    207219protected:
    208     Thread() = default;
     220    Thread();
    209221
    210222    void initializeInThread();
     
    239251    };
    240252
    241     JoinableState joinableState() { return m_joinableState; }
     253    JoinableState joinableState() const { return m_joinableState; }
    242254    void didBecomeDetached() { m_joinableState = Detached; }
    243255    void didExit();
    244256    void didJoin() { m_joinableState = Joined; }
    245     bool hasExited() { return m_didExit; }
     257    bool hasExited() const { return m_didExit; }
    246258
    247259    // These functions are only called from ThreadGroup.
     
    281293
    282294    JoinableState m_joinableState { Joinable };
    283     bool m_isShuttingDown { false };
    284     bool m_didExit { false };
    285     bool m_isDestroyedOnce { false };
     295    bool m_isShuttingDown : 1;
     296    bool m_didExit : 1;
     297    bool m_isDestroyedOnce : 1;
     298    bool m_isCompilationThread: 1;
     299    unsigned m_gcThreadType : 2;
    286300
    287301    // Lock & ParkingLot rely on ThreadSpecific. But Thread object can be destroyed even after ThreadSpecific things are destroyed.
     
    311325    void* m_apiData { nullptr };
    312326};
     327
     328inline Thread::Thread()
     329    : m_isShuttingDown(false)
     330    , m_didExit(false)
     331    , m_isDestroyedOnce(false)
     332    , m_isCompilationThread(false)
     333    , m_gcThreadType(static_cast<unsigned>(GCThreadType::None))
     334{
     335}
    313336
    314337inline Thread* Thread::currentMayBeNull()
     
    346369
    347370using WTF::Thread;
     371using WTF::GCThreadType;
    348372
    349373#if OS(WINDOWS)
  • trunk/Source/WTF/wtf/ThreadingPrimitives.h

    r237099 r245258  
    3131#pragma once
    3232
     33#include <limits.h>
    3334#include <wtf/FastMalloc.h>
    3435#include <wtf/Locker.h>
     
    4243#if USE(PTHREADS)
    4344#include <pthread.h>
     45#if !defined(PTHREAD_KEYS_MAX)
     46// PTHREAD_KEYS_MAX is not defined in bionic nor in Hurd, so explicitly define it here.
     47#define PTHREAD_KEYS_MAX 1024
     48#endif
     49#endif
     50
     51#if OS(WINDOWS) && CPU(X86)
     52#define THREAD_SPECIFIC_CALL __stdcall
     53#else
     54#define THREAD_SPECIFIC_CALL
    4455#endif
    4556
     
    5263using PlatformMutex = pthread_mutex_t;
    5364using PlatformCondition = pthread_cond_t;
     65using ThreadSpecificKey = pthread_key_t;
    5466#elif OS(WINDOWS)
    5567using ThreadIdentifier = uint32_t;
     
    5769using PlatformMutex = SRWLOCK;
    5870using PlatformCondition = CONDITION_VARIABLE;
     71using ThreadSpecificKey = DWORD;
    5972#else
    6073#error "Not supported platform"
     
    105118};
    106119
     120#if USE(PTHREADS)
     121
     122static constexpr ThreadSpecificKey InvalidThreadSpecificKey = PTHREAD_KEYS_MAX;
     123
     124inline void threadSpecificKeyCreate(ThreadSpecificKey* key, void (*destructor)(void *))
     125{
     126    int error = pthread_key_create(key, destructor);
     127    if (error)
     128        CRASH();
     129}
     130
     131inline void threadSpecificKeyDelete(ThreadSpecificKey key)
     132{
     133    int error = pthread_key_delete(key);
     134    if (error)
     135        CRASH();
     136}
     137
     138inline void threadSpecificSet(ThreadSpecificKey key, void* value)
     139{
     140    pthread_setspecific(key, value);
     141}
     142
     143inline void* threadSpecificGet(ThreadSpecificKey key)
     144{
     145    return pthread_getspecific(key);
     146}
     147
     148#elif OS(WINDOWS)
     149
     150static constexpr ThreadSpecificKey InvalidThreadSpecificKey = FLS_OUT_OF_INDEXES;
     151
     152inline void threadSpecificKeyCreate(ThreadSpecificKey* key, void (THREAD_SPECIFIC_CALL *destructor)(void *))
     153{
     154    DWORD flsKey = FlsAlloc(destructor);
     155    if (flsKey == FLS_OUT_OF_INDEXES)
     156        CRASH();
     157
     158    *key = flsKey;
     159}
     160
     161inline void threadSpecificKeyDelete(ThreadSpecificKey key)
     162{
     163    FlsFree(key);
     164}
     165
     166inline void threadSpecificSet(ThreadSpecificKey key, void* data)
     167{
     168    FlsSetValue(key, data);
     169}
     170
     171inline void* threadSpecificGet(ThreadSpecificKey key)
     172{
     173    return FlsGetValue(key);
     174}
     175
     176#endif
     177
    107178} // namespace WTF
    108179
  • trunk/Source/WTF/wtf/win/ThreadSpecificWin.cpp

    r240636 r245258  
    3535DWORD* flsKeys()
    3636{
    37     static DWORD keys[kMaxFlsKeySize];
     37    static DWORD keys[maxFlsKeySize];
    3838    return keys;
    3939}
  • trunk/Source/WebCore/ChangeLog

    r245253 r245258  
     12019-05-13  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [WTF] Simplify GCThread and CompilationThread flags by adding them to WTF::Thread
     4        https://bugs.webkit.org/show_bug.cgi?id=197146
     5
     6        Reviewed by Saam Barati.
     7
     8        * Modules/indexeddb/IDBDatabase.cpp:
     9        (WebCore::IDBDatabase::hasPendingActivity const):
     10        * Modules/indexeddb/IDBRequest.cpp:
     11        (WebCore::IDBRequest::hasPendingActivity const):
     12        * Modules/indexeddb/IDBTransaction.cpp:
     13        (WebCore::IDBTransaction::hasPendingActivity const):
     14
    1152019-05-13  Geoffrey Garen  <ggaren@apple.com>
    216
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp

    r243887 r245258  
    7878bool IDBDatabase::hasPendingActivity() const
    7979{
    80     ASSERT(&originThread() == &Thread::current() || mayBeGCThread());
     80    ASSERT(&originThread() == &Thread::current() || Thread::mayBeGCThread());
    8181
    8282    if (m_closedInServer || isContextStopped())
  • trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp

    r244674 r245258  
    268268bool IDBRequest::hasPendingActivity() const
    269269{
    270     ASSERT(&originThread() == &Thread::current() || mayBeGCThread());
     270    ASSERT(&originThread() == &Thread::current() || Thread::mayBeGCThread());
    271271    return !m_contextStopped && m_hasPendingActivity;
    272272}
  • trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

    r244674 r245258  
    332332bool IDBTransaction::hasPendingActivity() const
    333333{
    334     ASSERT(&m_database->originThread() == &Thread::current() || mayBeGCThread());
     334    ASSERT(&m_database->originThread() == &Thread::current() || Thread::mayBeGCThread());
    335335    return !m_contextStopped && m_state != IndexedDB::TransactionState::Finished;
    336336}
Note: See TracChangeset for help on using the changeset viewer.