Changeset 43507 in webkit


Ignore:
Timestamp:
May 11, 2009, 12:49:04 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-05-11 Dmitry Titov <[email protected]>

Reviewed by Alexey Proskuryakov and Adam Roben.

https://bugs.webkit.org/show_bug.cgi?id=25348
Change WTF::ThreadIdentifier to be an actual (but wrapped) thread id, remove ThreadMap.

  • wtf/Threading.h: (WTF::ThreadIdentifier::ThreadIdentifier): (WTF::ThreadIdentifier::isValid): (WTF::ThreadIdentifier::invalidate): (WTF::ThreadIdentifier::platformId): ThreadIdentifier is now a class, containing a PlatformThreadIdentifier and methods that are used across the code on thread ids: construction, comparisons, check for 'valid' state etc. '0' is used as invalid id, which happens to just work with all platform-specific thread id implementations.

All the following files repeatedly reflect the new ThreadIdentifier for each platform.
We remove ThreadMap and threadMapMutex from all of them, remove the functions that
populated/searched/cleared the map and add platform-specific comparison operators
for ThreadIdentifier.

There are specific temporary workarounds for Safari 4 beta on OSX and Win32 since the
public build uses WTF threading functions with old type of ThreadingIdentifier.
The next time Safari 4 is rebuilt, it will 'automatically' pick up the new type and new
functions so the deprecated ones can be removed.

  • wtf/gtk/ThreadingGtk.cpp: (WTF::ThreadIdentifier::operator==): (WTF::ThreadIdentifier::operator!=): (WTF::initializeThreading): (WTF::createThreadInternal): (WTF::waitForThreadCompletion): (WTF::currentThread):
  • wtf/ThreadingNone.cpp: (WTF::ThreadIdentifier::operator==): (WTF::ThreadIdentifier::operator!=):
  • wtf/ThreadingPthreads.cpp: (WTF::ThreadIdentifier::operator==): (WTF::ThreadIdentifier::operator!=): (WTF::initializeThreading): (WTF::createThreadInternal): (WTF::waitForThreadCompletion): (WTF::detachThread): (WTF::currentThread): (WTF::waitForThreadCompletion): This is a workaround for Safari 4 beta on Mac. Safari 4 is linked against old definition of ThreadIdentifier so it treats it as uint32_t. This 'old' variant of waitForThreadCompletion takes uint32_t and has the old decorated name, so Safari can load it from JavaScriptCore library. The other functions (CurrentThread() etc) happen to match their previous decorated names and, while they return pthread_t now, it is a pointer which round-trips through a uint32_t. This function will be removed as soon as Safari 4 will release next public build.
  • wtf/qt/ThreadingQt.cpp: (WTF::ThreadIdentifier::operator==): (WTF::ThreadIdentifier::operator!=): (WTF::initializeThreading): (WTF::createThreadInternal): (WTF::waitForThreadCompletion): (WTF::currentThread):
  • wtf/ThreadingWin.cpp: (WTF::ThreadIdentifier::operator==): (WTF::ThreadIdentifier::operator!=): (WTF::initializeThreading): (WTF::createThreadInternal): All the platforms (except Windows) used a sequential counter as a thread ID and mapped it into platform ID. Windows was using native thread id and mapped it into thread handle. Since we can always obtain a thread handle by thread id, createThread now closes the handle. (WTF::waitForThreadCompletion): obtains another one using OpenThread(id) API. If can not obtain a handle, it means the thread already exited. (WTF::detachThread): (WTF::currentThread): (WTF::detachThreadDeprecated): old function, renamed (for Win Safari 4 beta which uses it for now). (WTF::waitForThreadCompletionDeprecated): same. (WTF::currentThreadDeprecated): same. (WTF::createThreadDeprecated): same.
  • bytecode/SamplingTool.h:
  • bytecode/SamplingTool.cpp: Use DEFINE_STATIC_LOCAL for a static ThreadIdentifier variable, to avoid static constructor.
  • JavaScriptCore.exp: export lists - updated decorated names of the WTF threading functions since they now take a different type as a parameter.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: ditto for Windows, plus added "deprecated" functions that take old parameter type - turns out public beta of Safari 4 uses those, so they need to be kept along for a while.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore_debug.def: ditto.

WebCore:

2009-05-11 Dmitry Titov <[email protected]>

Reviewed by Alexey Proskuryakov and Adam Roben.

https://bugs.webkit.org/show_bug.cgi?id=25348
Change WTF::ThreadIdentifier to be an actual (but wrapped) thread id, remove ThreadMap.

Most of the change is in WTF.
Unless noted, all the following files changed to use the new ThreadIdentifier::isValid()
method instead of just doing 'if(m_threadID)' kind of checks, since ThreadIdentifier
is now a class rather then an integer.
Also, there is no need to initialize threadID in constructors to 0 now.

  • dom/XMLTokenizerLibxml2.cpp: (WebCore::libxmlLoaderThread): use DEFINE_STATIC_LOCAL and accessor function for static thread id, since now ThreadIdentifier needs construction and we avoid having global initializers. (WebCore::matchFunc): use the new accessor function. (WebCore::openFunc): ditto. (WebCore::createStringParser): ditto. (WebCore::createMemoryParser): ditto.
  • loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open):
  • platform/sql/SQLiteDatabase.cpp: (WebCore::SQLiteDatabase::SQLiteDatabase): (WebCore::SQLiteDatabase::close):
  • storage/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): remove m_threadID from debug output.
  • storage/LocalStorageThread.cpp: (WebCore::LocalStorageThread::start): (WebCore::LocalStorageThread::scheduleImport): (WebCore::LocalStorageThread::scheduleSync): (WebCore::LocalStorageThread::terminate):
  • workers/WorkerThread.cpp: (WebCore::WorkerThread::start): (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start):

WebKit/win:

2009-05-11 Dmitry Titov <[email protected]>

Reviewed by Alexey Proskuryakov and Adam Roben.

https://bugs.webkit.org/show_bug.cgi?id=25348
Change WTF::ThreadIdentifier to be an actual (but wrapped) thread id, remove ThreadMap.

Most of the change is in WTF and WebCore.

  • WebKit.vcproj/WebKit.def: replaced decorated names of WTF threading functions with new ones. Also, aliased the old implementations so the public Safari 4 beta can load the old WTF functions which it uses. Next time Safari 4 builds, it will pick up new functions and the deprecated ones can be removed.
  • WebKit.vcproj/WebKit_debug.def: same.
Location:
trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r43506 r43507  
     12009-05-11  Dmitry Titov  <[email protected]>
     2
     3        Reviewed by Alexey Proskuryakov and Adam Roben.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=25348
     6        Change WTF::ThreadIdentifier to be an actual (but wrapped) thread id, remove ThreadMap.
     7
     8        * wtf/Threading.h:
     9        (WTF::ThreadIdentifier::ThreadIdentifier):
     10        (WTF::ThreadIdentifier::isValid):
     11        (WTF::ThreadIdentifier::invalidate):
     12        (WTF::ThreadIdentifier::platformId):
     13        ThreadIdentifier is now a class, containing a PlatformThreadIdentifier and
     14        methods that are used across the code on thread ids: construction, comparisons,
     15        check for 'valid' state etc. '0' is used as invalid id, which happens to just work
     16        with all platform-specific thread id implementations.
     17
     18        All the following files repeatedly reflect the new ThreadIdentifier for each platform.
     19        We remove ThreadMap and threadMapMutex from all of them, remove the functions that
     20        populated/searched/cleared the map and add platform-specific comparison operators
     21        for ThreadIdentifier.
     22
     23        There are specific temporary workarounds for Safari 4 beta on OSX and Win32 since the
     24        public build uses WTF threading functions with old type of ThreadingIdentifier.
     25        The next time Safari 4 is rebuilt, it will 'automatically' pick up the new type and new
     26        functions so the deprecated ones can be removed.
     27
     28        * wtf/gtk/ThreadingGtk.cpp:
     29        (WTF::ThreadIdentifier::operator==):
     30        (WTF::ThreadIdentifier::operator!=):
     31        (WTF::initializeThreading):
     32        (WTF::createThreadInternal):
     33        (WTF::waitForThreadCompletion):
     34        (WTF::currentThread):
     35
     36        * wtf/ThreadingNone.cpp:
     37        (WTF::ThreadIdentifier::operator==):
     38        (WTF::ThreadIdentifier::operator!=):
     39
     40        * wtf/ThreadingPthreads.cpp:
     41        (WTF::ThreadIdentifier::operator==):
     42        (WTF::ThreadIdentifier::operator!=):
     43        (WTF::initializeThreading):
     44        (WTF::createThreadInternal):
     45        (WTF::waitForThreadCompletion):
     46        (WTF::detachThread):
     47        (WTF::currentThread):
     48        (WTF::waitForThreadCompletion): This is a workaround for Safari 4 beta on Mac.
     49        Safari 4 is linked against old definition of ThreadIdentifier so it treats it as uint32_t.
     50        This 'old' variant of waitForThreadCompletion takes uint32_t and has the old decorated name, so Safari can
     51        load it from JavaScriptCore library. The other functions (CurrentThread() etc) happen to match their previous
     52        decorated names and, while they return pthread_t now, it is a pointer which round-trips through a uint32_t.
     53        This function will be removed as soon as Safari 4 will release next public build.
     54
     55        * wtf/qt/ThreadingQt.cpp:
     56        (WTF::ThreadIdentifier::operator==):
     57        (WTF::ThreadIdentifier::operator!=):
     58        (WTF::initializeThreading):
     59        (WTF::createThreadInternal):
     60        (WTF::waitForThreadCompletion):
     61        (WTF::currentThread):
     62
     63        * wtf/ThreadingWin.cpp:
     64        (WTF::ThreadIdentifier::operator==):
     65        (WTF::ThreadIdentifier::operator!=):
     66        (WTF::initializeThreading):
     67        (WTF::createThreadInternal): All the platforms (except Windows) used a sequential
     68        counter as a thread ID and mapped it into platform ID. Windows was using native thread
     69        id and mapped it into thread handle. Since we can always obtain a thread handle
     70        by thread id, createThread now closes the handle.
     71        (WTF::waitForThreadCompletion): obtains another one using OpenThread(id) API. If can not obtain a handle,
     72        it means the thread already exited.
     73        (WTF::detachThread):
     74        (WTF::currentThread):
     75        (WTF::detachThreadDeprecated): old function, renamed (for Win Safari 4 beta which uses it for now).
     76        (WTF::waitForThreadCompletionDeprecated): same.
     77        (WTF::currentThreadDeprecated): same.
     78        (WTF::createThreadDeprecated): same.
     79
     80        * bytecode/SamplingTool.h:
     81        * bytecode/SamplingTool.cpp: Use DEFINE_STATIC_LOCAL for a static ThreadIdentifier variable, to avoid static constructor.
     82
     83        * JavaScriptCore.exp: export lists - updated decorated names of the WTF threading functions
     84        since they now take a different type as a parameter.
     85        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: ditto for Windows, plus added "deprecated" functions
     86        that take old parameter type - turns out public beta of Safari 4 uses those, so they need to be kept along for a while.
     87        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore_debug.def: ditto.
     88
    1892009-05-11  Darin Adler  <[email protected]>
    290
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r43479 r43507  
    280280__ZN3WTF12createThreadEPFPvS0_ES0_
    281281__ZN3WTF12createThreadEPFPvS0_ES0_PKc
    282 __ZN3WTF12detachThreadEj
     282__ZN3WTF12detachThreadENS_16ThreadIdentifierE
    283283__ZN3WTF12isMainThreadEv
    284284__ZN3WTF12randomNumberEv
     
    301301__ZN3WTF21RefCountedLeakCounterC1EPKc
    302302__ZN3WTF21RefCountedLeakCounterD1Ev
    303 __ZN3WTF23waitForThreadCompletionEjPPv
     303__ZN3WTF23waitForThreadCompletionENS_16ThreadIdentifierEPPv
    304304__ZN3WTF27releaseFastMallocFreeMemoryEv
    305305__ZN3WTF28setMainThreadCallbacksPausedEb
     
    363363__ZNK3JSC9HashTable11deleteTableEv
    364364__ZNK3WTF8Collator7collateEPKtmS2_m
     365__ZNK3WTF16ThreadIdentifiereqERKS0_
     366__ZNK3WTF16ThreadIdentifierneERKS0_
    365367__ZTVN3JSC12StringObjectE
    366368__ZTVN3JSC14JSGlobalObjectE
     
    372374_jscore_fastmalloc_introspection
    373375_kJSClassDefinitionEmpty
     376__ZN3WTF23waitForThreadCompletionEjPPv
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r43489 r43507  
    3333    ??4UString@JSC@@QAEAAV01@PBD@Z
    3434    ??8JSC@@YA_NABVUString@0@0@Z
     35    ??8ThreadIdentifier@WTF@@QBE_NABV01@@Z
    3536    ?UTF8String@UString@JSC@@QBE?AVCString@2@_N@Z
    3637    ?add@Identifier@JSC@@SA?AV?$PassRefPtr@URep@UString@JSC@@@WTF@@PAVExecState@2@PBD@Z
     
    7576    ?createStructure@JSByteArray@JSC@@SA?AV?$PassRefPtr@VStructure@JSC@@@WTF@@VJSValue@2@@Z
    7677    ?createTable@HashTable@JSC@@ABEXPAVJSGlobalData@2@@Z
    77     ?createThread@WTF@@YAIP6APAXPAX@Z0@Z
    78     ?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z
    79     ?currentThread@WTF@@YAIXZ
     78    ?createThread@WTF@@YA?AVThreadIdentifier@1@P6APAXPAX@Z0PBD@Z
     79    ?currentThread@WTF@@YA?AVThreadIdentifier@1@XZ
    8080    ?currentTime@WTF@@YANXZ
    8181    ?decrement@RefCountedLeakCounter@WTF@@QAEXXZ
     
    9797    ?destroy@Rep@UString@JSC@@QAEXXZ
    9898    ?detach@Debugger@JSC@@QAEXPAVJSGlobalObject@2@@Z
    99     ?detachThread@WTF@@YAXI@Z
     99    ?detachThread@WTF@@YAXVThreadIdentifier@1@@Z
    100100    ?equal@Identifier@JSC@@SA_NPBURep@UString@2@PBD@Z
    101101    ?equal@JSC@@YA_NPBURep@UString@1@0@Z
     
    255255    ?unwrappedObject@JSObject@JSC@@UAEPAV12@XZ
    256256    ?wait@ThreadCondition@WTF@@QAEXAAVMutex@2@@Z
    257     ?waitForThreadCompletion@WTF@@YAHIPAPAX@Z
     257    ?waitForThreadCompletion@WTF@@YAHVThreadIdentifier@1@PAPAX@Z
    258258    WTFLog
    259259    WTFLogVerbose
     
    266266    ?setDumpsGeneratedCode@BytecodeGenerator@JSC@@SAX_N@Z
    267267    ?putDirectFunction@JSObject@JSC@@QAEXPAVExecState@2@PAVInternalFunction@2@I@Z
     268    ?createThreadDeprecated@WTF@@YAIP6APAXPAX@Z0PBD@Z
     269    ?currentThreadDeprecated@WTF@@YAIXZ
     270    ?detachThreadDeprecated@WTF@@YAXI@Z
     271    ?waitForThreadCompletionDeprecated@WTF@@YAHIPAPAX@Z
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore_debug.def

    r43489 r43507  
    3333    ??4UString@JSC@@QAEAAV01@PBD@Z
    3434    ??8JSC@@YA_NABVUString@0@0@Z
     35    ??8ThreadIdentifier@WTF@@QBE_NABV01@@Z
    3536    ?UTF8String@UString@JSC@@QBE?AVCString@2@_N@Z
    3637    ?add@Identifier@JSC@@SA?AV?$PassRefPtr@URep@UString@JSC@@@WTF@@PAVExecState@2@PBD@Z
     
    7576    ?createStructure@JSByteArray@JSC@@SA?AV?$PassRefPtr@VStructure@JSC@@@WTF@@VJSValue@2@@Z
    7677    ?createTable@HashTable@JSC@@ABEXPAVJSGlobalData@2@@Z
    77     ?createThread@WTF@@YAIP6APAXPAX@Z0@Z
    78     ?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z
    79     ?currentThread@WTF@@YAIXZ
     78    ?createThread@WTF@@YA?AVThreadIdentifier@1@P6APAXPAX@Z0PBD@Z
     79    ?currentThread@WTF@@YA?AVThreadIdentifier@1@XZ
    8080    ?currentTime@WTF@@YANXZ
    8181    ?decrement@RefCountedLeakCounter@WTF@@QAEXXZ
     
    9797    ?destroy@Rep@UString@JSC@@QAEXXZ
    9898    ?detach@Debugger@JSC@@QAEXPAVJSGlobalObject@2@@Z
    99     ?detachThread@WTF@@YAXI@Z
     99    ?detachThread@WTF@@YAXVThreadIdentifier@1@@Z
    100100    ?equal@Identifier@JSC@@SA_NPBURep@UString@2@PBD@Z
    101101    ?equal@JSC@@YA_NPBURep@UString@1@0@Z
     
    255255    ?unwrappedObject@JSObject@JSC@@UAEPAV12@XZ
    256256    ?wait@ThreadCondition@WTF@@QAEXAAVMutex@2@@Z
    257     ?waitForThreadCompletion@WTF@@YAHIPAPAX@Z
     257    ?waitForThreadCompletion@WTF@@YAHVThreadIdentifier@1@PAPAX@Z
    258258    WTFLog
    259259    WTFLogVerbose
     
    266266    ?setDumpsGeneratedCode@BytecodeGenerator@JSC@@SAX_N@Z
    267267    ?putDirectFunction@JSObject@JSC@@QAEXPAVExecState@2@PAVInternalFunction@2@I@Z
     268    ?createThreadDeprecated@WTF@@YAIP6APAXPAX@Z0PBD@Z
     269    ?currentThreadDeprecated@WTF@@YAIXZ
     270    ?detachThreadDeprecated@WTF@@YAXI@Z
     271    ?waitForThreadCompletionDeprecated@WTF@@YAHIPAPAX@Z
  • trunk/JavaScriptCore/bytecode/SamplingTool.cpp

    r43397 r43507  
    122122bool SamplingThread::s_running = false;
    123123unsigned SamplingThread::s_hertz = 10000;
    124 ThreadIdentifier SamplingThread::s_samplingThread;
     124
     125ThreadIdentifier& SamplingThread::samplingThread() {
     126    DEFINE_STATIC_LOCAL(ThreadIdentifier, staticSamplingThread, ());
     127    return staticSamplingThread;
     128}
    125129
    126130void* SamplingThread::threadStartFunc(void*)
     
    147151    s_hertz = hertz;
    148152
    149     s_samplingThread = createThread(threadStartFunc, 0, "JavaScriptCore::Sampler");
     153    samplingThread() = createThread(threadStartFunc, 0, "JavaScriptCore::Sampler");
    150154}
    151155
     
    154158    ASSERT(s_running);
    155159    s_running = false;
    156     waitForThreadCompletion(s_samplingThread, 0);
     160    waitForThreadCompletion(samplingThread(), 0);
    157161}
    158162
  • trunk/JavaScriptCore/bytecode/SamplingTool.h

    r43397 r43507  
    126126        static bool s_running;
    127127        static unsigned s_hertz;
    128         static ThreadIdentifier s_samplingThread;
     128
     129        static ThreadIdentifier& samplingThread();
    129130
    130131        static void start(unsigned hertz=10000);
  • trunk/JavaScriptCore/wtf/CrossThreadRefCounted.h

    r43392 r43507  
    7575            : m_threadSafeRefCounter(threadedCounter)
    7676            , m_data(data)
    77 #ifndef NDEBUG
    78             , m_threadId(0)
    79 #endif
    8077        {
    8178        }
     
    10097    void CrossThreadRefCounted<T>::ref()
    10198    {
    102         ASSERT(!m_threadId || m_threadId == currentThread());
     99        ASSERT(!m_threadId.isValid() || m_threadId == currentThread());
    103100        m_refCounter.ref();
    104101#ifndef NDEBUG
     
    108105        // is a heuristic but it seems to always work and has helped
    109106        // find some bugs.
    110         if (!m_threadId && m_refCounter.refCount() == 2)
     107        if (!m_threadId.isValid() && m_refCounter.refCount() == 2)
    111108            m_threadId = currentThread();
    112109#endif
     
    116113    void CrossThreadRefCounted<T>::deref()
    117114    {
    118         ASSERT(!m_threadId || m_threadId == currentThread());
     115        ASSERT(!m_threadId.isValid() || m_threadId == currentThread());
    119116        if (m_refCounter.derefBase()) {
    120117            threadSafeDeref();
     
    125122            // is safe to be passed to another thread at this point.
    126123            if (m_threadId && m_refCounter.refCount() == 1)
    127                 m_threadId = 0;
     124                m_threadId.invalidate();
    128125#endif
    129126        }
  • trunk/JavaScriptCore/wtf/Threading.h

    r43392 r43507  
    8686typedef struct _GMutex GMutex;
    8787typedef struct _GCond GCond;
     88typedef struct _GThread GThread;
    8889#endif
    8990
     
    9293QT_BEGIN_NAMESPACE
    9394class QMutex;
     95class QThread;
    9496class QWaitCondition;
    9597QT_END_NAMESPACE
     
    106108namespace WTF {
    107109
    108 typedef uint32_t ThreadIdentifier;
    109 typedef void* (*ThreadFunction)(void* argument);
    110 
    111 // Returns 0 if thread creation failed.
    112 // The thread name must be a literal since on some platforms it's passed in to the thread.
    113 ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
    114 
    115 // Internal platform-specific createThread implementation.
    116 ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);
    117 
    118 // Called in the thread during initialization.
    119 // Helpful for platforms where the thread name must be set from within the thread.
    120 void setThreadNameInternal(const char* threadName);
    121 
    122 ThreadIdentifier currentThread();
    123 bool isMainThread();
    124 int waitForThreadCompletion(ThreadIdentifier, void**);
    125 void detachThread(ThreadIdentifier);
    126 
    127110#if USE(PTHREADS)
    128111typedef pthread_mutex_t PlatformMutex;
    129112typedef pthread_cond_t PlatformCondition;
     113typedef pthread_t PlatformThreadIdentifier;
    130114#elif PLATFORM(GTK)
    131115typedef GOwnPtr<GMutex> PlatformMutex;
    132116typedef GOwnPtr<GCond> PlatformCondition;
     117typedef GThread* PlatformThreadIdentifier;
    133118#elif PLATFORM(QT)
    134119typedef QT_PREPEND_NAMESPACE(QMutex)* PlatformMutex;
    135120typedef QT_PREPEND_NAMESPACE(QWaitCondition)* PlatformCondition;
     121typedef QT_PREPEND_NAMESPACE(QThread)* PlatformThreadIdentifier;
    136122#elif PLATFORM(WIN_OS)
    137123struct PlatformMutex {
     
    150136    void signal(bool unblockAll);
    151137};
     138typedef unsigned PlatformThreadIdentifier;
    152139#else
    153140typedef void* PlatformMutex;
     
    155142#endif
    156143   
     144// Platform-independent wrapper for thread id. Assignable and copyable.
     145// A valid ThreadIdentifier is usually returned from createThread(...) or currentThread() functions.
     146// ThreadIdentifier remains valid for as long as its thread is alive and is not automatically invalidated
     147// when thread terminates. Since platform-dependent thread ids can be recycled, stale ThreadIdentifier
     148// may reference a completely unrelated thread after its original thread terminates.
     149class ThreadIdentifier {
     150public:
     151    ThreadIdentifier()
     152        : m_platformId(0)
     153    {
     154        ASSERT(!isValid());
     155    }
     156
     157    explicit ThreadIdentifier(PlatformThreadIdentifier platformId)
     158        : m_platformId(platformId)
     159    {
     160        ASSERT(isValid());
     161    }
     162
     163    bool isValid() const  { return m_platformId; }
     164    void invalidate() { m_platformId = 0; }
     165
     166    bool operator==(const ThreadIdentifier&) const;
     167    bool operator!=(const ThreadIdentifier&) const;
     168
     169    PlatformThreadIdentifier platformId() const { return m_platformId;  }
     170
     171private:
     172    PlatformThreadIdentifier m_platformId;
     173};
     174
     175typedef void* (*ThreadFunction)(void* argument);
     176
     177// Returns invalid identifier if thread creation failed.
     178// The thread name must be a literal since on some platforms it's passed in to the thread.
     179ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
     180
     181// Internal platform-specific createThread implementation.
     182ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);
     183
     184// Called in the thread during initialization.
     185// Helpful for platforms where the thread name must be set from within the thread.
     186void setThreadNameInternal(const char* threadName);
     187
     188ThreadIdentifier currentThread();
     189bool isMainThread();
     190int waitForThreadCompletion(ThreadIdentifier, void**);
     191void detachThread(ThreadIdentifier);
     192
    157193class Mutex : Noncopyable {
    158194public:
  • trunk/JavaScriptCore/wtf/ThreadingNone.cpp

    r43392 r43507  
    3333namespace WTF {
    3434
     35bool ThreadIdentifier::operator==(const ThreadIdentifier&) const { return true; }
     36bool ThreadIdentifier::operator!=(const ThreadIdentifier&) const { return false; }
     37
    3538void initializeThreading() { }
    3639ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char*) { return ThreadIdentifier(); }
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r43392 r43507  
    4949namespace WTF {
    5050
    51 typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap;
     51bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
     52{
     53    return pthread_equal(m_platformId, another.m_platformId);
     54}
     55
     56bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
     57{
     58    return !pthread_equal(m_platformId, another.m_platformId);
     59}
    5260
    5361static Mutex* atomicallyInitializedStaticMutex;
     
    5765#endif
    5866
    59 static Mutex& threadMapMutex()
    60 {
    61     DEFINE_STATIC_LOCAL(Mutex, mutex, ());
    62     return mutex;
    63 }
    64 
    6567void initializeThreading()
    6668{
    6769    if (!atomicallyInitializedStaticMutex) {
    6870        atomicallyInitializedStaticMutex = new Mutex;
    69         threadMapMutex();
    7071        initializeRandomNumberGenerator();
    7172#if !PLATFORM(DARWIN) || PLATFORM(CHROMIUM)
     
    8586{
    8687    atomicallyInitializedStaticMutex->unlock();
    87 }
    88 
    89 static ThreadMap& threadMap()
    90 {
    91     DEFINE_STATIC_LOCAL(ThreadMap, map, ());
    92     return map;
    93 }
    94 
    95 static ThreadIdentifier identifierByPthreadHandle(const pthread_t& pthreadHandle)
    96 {
    97     MutexLocker locker(threadMapMutex());
    98 
    99     ThreadMap::iterator i = threadMap().begin();
    100     for (; i != threadMap().end(); ++i) {
    101         if (pthread_equal(i->second, pthreadHandle))
    102             return i->first;
    103     }
    104 
    105     return 0;
    106 }
    107 
    108 static ThreadIdentifier establishIdentifierForPthreadHandle(pthread_t& pthreadHandle)
    109 {
    110     ASSERT(!identifierByPthreadHandle(pthreadHandle));
    111 
    112     MutexLocker locker(threadMapMutex());
    113 
    114     static ThreadIdentifier identifierCount = 1;
    115 
    116     threadMap().add(identifierCount, pthreadHandle);
    117    
    118     return identifierCount++;
    119 }
    120 
    121 static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id)
    122 {
    123     MutexLocker locker(threadMapMutex());
    124    
    125     return threadMap().get(id);
    126 }
    127 
    128 static void clearPthreadHandleForIdentifier(ThreadIdentifier id)
    129 {
    130     MutexLocker locker(threadMapMutex());
    131 
    132     ASSERT(threadMap().contains(id));
    133    
    134     threadMap().remove(id);
    13588}
    13689
     
    165118    if (pthread_create(&threadHandle, 0, runThreadWithRegistration, static_cast<void*>(threadData))) {
    166119        LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
    167         return 0;
    168     }
    169     return establishIdentifierForPthreadHandle(threadHandle);
     120        return ThreadIdentifier();
     121    }
     122    return ThreadIdentifier(threadHandle);
    170123}
    171124#else
     
    175128    if (pthread_create(&threadHandle, 0, entryPoint, data)) {
    176129        LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
    177         return 0;
    178     }
    179 
    180     return establishIdentifierForPthreadHandle(threadHandle);
     130        return ThreadIdentifier();
     131    }
     132
     133    return ThreadIdentifier(threadHandle);
    181134}
    182135#endif
     
    193146int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    194147{
    195     ASSERT(threadID);
    196    
    197     pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID);
     148    ASSERT(threadID.isValid());
     149   
     150    pthread_t pthreadHandle = threadID.platformId();
    198151 
    199152    int joinResult = pthread_join(pthreadHandle, result);
    200153    if (joinResult == EDEADLK)
    201         LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID);
     154        LOG_ERROR("ThreadIdentifier %p was found to be deadlocked trying to quit", pthreadHandle);
    202155       
    203     clearPthreadHandleForIdentifier(threadID);
    204156    return joinResult;
    205157}
     
    207159void detachThread(ThreadIdentifier threadID)
    208160{
    209     ASSERT(threadID);
    210    
    211     pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID);
     161    ASSERT(threadID.isValid());
     162   
     163    pthread_t pthreadHandle = threadID.platformId();
    212164   
    213165    pthread_detach(pthreadHandle);
    214    
    215     clearPthreadHandleForIdentifier(threadID);
    216166}
    217167
    218168ThreadIdentifier currentThread()
    219169{
    220     pthread_t currentThread = pthread_self();
    221     if (ThreadIdentifier id = identifierByPthreadHandle(currentThread))
    222         return id;
    223     return establishIdentifierForPthreadHandle(currentThread);
     170    return ThreadIdentifier(pthread_self());
    224171}
    225172
     
    315262    ASSERT_UNUSED(result, !result);
    316263}
    317    
     264
     265// Derecated function. Safari 4 beta, until recompiled next time, uses ThreadIdentifier as uint32_t.
     266// pthread_t is a pointer. So they get a pointer casted into uint32_t from CurrentThread()
     267// and then pass it here. We cast it back to pointer. This is an ugly hack which is very temporary
     268// and will be removed once next public build of Safari 4 is released.
     269int waitForThreadCompletion(uint32_t threadID, void** result)
     270{
     271    pthread_t pthreadHandle = reinterpret_cast<pthread_t>(threadID);
     272
     273    int joinResult = pthread_join(pthreadHandle, result);
     274    if (joinResult == EDEADLK)
     275        LOG_ERROR("ThreadIdentifier %p was found to be deadlocked trying to quit", pthreadHandle);
     276
     277    return joinResult;
     278}
     279
    318280} // namespace WTF
    319281
  • trunk/JavaScriptCore/wtf/ThreadingWin.cpp

    r43392 r43507  
    9999namespace WTF {
    100100
     101bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
     102{
     103    return m_platformId == another.m_platformId;
     104}
     105
     106bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
     107{
     108    return m_platformId != another.m_platformId;
     109}
     110
    101111// MS_VC_EXCEPTION, THREADNAME_INFO, and setThreadNameInternal all come from <http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>.
    102112static const DWORD MS_VC_EXCEPTION = 0x406D1388;
     
    140150static ThreadIdentifier mainThreadIdentifier;
    141151
    142 static Mutex& threadMapMutex()
    143 {
    144     static Mutex mutex;
    145     return mutex;
    146 }
    147 
    148152void initializeThreading()
    149153{
    150154    if (!atomicallyInitializedStaticMutex) {
    151155        atomicallyInitializedStaticMutex = new Mutex;
    152         threadMapMutex();
    153156        initializeRandomNumberGenerator();
    154157        initializeMainThread();
     
    158161}
    159162
    160 static HashMap<DWORD, HANDLE>& threadMap()
    161 {
    162     static HashMap<DWORD, HANDLE> map;
    163     return map;
    164 }
    165 
    166 static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle)
    167 {
    168     MutexLocker locker(threadMapMutex());
    169     ASSERT(!threadMap().contains(threadID));
    170     threadMap().add(threadID, threadHandle);
    171 }
    172 
    173 static HANDLE threadHandleForIdentifier(ThreadIdentifier id)
    174 {
    175     MutexLocker locker(threadMapMutex());
    176     return threadMap().get(id);
    177 }
    178 
    179 static void clearThreadHandleForIdentifier(ThreadIdentifier id)
    180 {
    181     MutexLocker locker(threadMapMutex());
    182     ASSERT(threadMap().contains(id));
    183     threadMap().remove(id);
    184 }
    185 
    186163struct ThreadFunctionInvocation {
    187164    ThreadFunctionInvocation(ThreadFunction function, void* data) : function(function), data(data) {}
     
    209186{
    210187    unsigned threadIdentifier = 0;
    211     ThreadIdentifier threadID = 0;
    212188    ThreadFunctionInvocation* invocation = new ThreadFunctionInvocation(entryPoint, data);
    213189    HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThreadEntryPoint, invocation, 0, &threadIdentifier));
    214190    if (!threadHandle) {
    215191        LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld", entryPoint, data, errno);
    216         return 0;
    217     }
    218 
    219     threadID = static_cast<ThreadIdentifier>(threadIdentifier);
    220     storeThreadHandleByIdentifier(threadIdentifier, threadHandle);
    221 
    222     return threadID;
     192        return ThreadIdentifier();
     193    }
     194    // Closes handle only, since we don't need it. The new thread runs until it exits.
     195    CloseHandle(threadHandle);
     196
     197    return ThreadIdentifier(threadIdentifier);
    223198}
    224199
    225200int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    226201{
    227     ASSERT(threadID);
     202    ASSERT(threadID.isValid());
    228203   
    229     HANDLE threadHandle = threadHandleForIdentifier(threadID);
     204    unsigned threadIdentifier = threadID.platformId();
     205    HANDLE threadHandle = OpenThread(SYNCHRONIZE, FALSE, threadIdentifier);
     206    // If thread already exited, return immediately.
    230207    if (!threadHandle)
    231         LOG_ERROR("ThreadIdentifier %u did not correspond to an active thread when trying to quit", threadID);
     208        return WAIT_OBJECT_0;
    232209 
    233210    DWORD joinResult = WaitForSingleObject(threadHandle, INFINITE);
    234211    if (joinResult == WAIT_FAILED)
    235         LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID);
     212        LOG_ERROR("ThreadIdentifier %p was found to be deadlocked trying to quit", threadHandle);
    236213
    237214    CloseHandle(threadHandle);
    238     clearThreadHandleForIdentifier(threadID);
    239215
    240216    return joinResult;
    241217}
    242218
    243 void detachThread(ThreadIdentifier threadID)
    244 {
    245     ASSERT(threadID);
    246    
    247     HANDLE threadHandle = threadHandleForIdentifier(threadID);
    248     if (threadHandle)
    249         CloseHandle(threadHandle);
    250     clearThreadHandleForIdentifier(threadID);
     219void detachThread(ThreadIdentifier)
     220{
    251221}
    252222
    253223ThreadIdentifier currentThread()
    254224{
    255     return static_cast<ThreadIdentifier>(GetCurrentThreadId());
     225    return ThreadIdentifier(GetCurrentThreadId());
    256226}
    257227
     
    471441}
    472442
     443// Deprecated functions. The current build of Safari 4 beta is linked with them so we need to provide
     444// the implementation taking PlatformThreadIdentifier instead of ThreadIdentifier. These are not declared
     445// in .h file so the next time Safari is built it will 'automatically' switch to new functions.
     446// Then deprecated ones can be removed from this file and from JavaScriptCore.def and WebKit.def files.
     447// In WebKit.def file, these functions are 'renamed' so their name does not have 'Deprecated' part - this
     448// is to avoid having 2 functions with only different type of return value.
     449void detachThreadDeprecated(PlatformThreadIdentifier)
     450{
     451}
     452
     453int waitForThreadCompletionDeprecated(PlatformThreadIdentifier threadID, void** result)
     454{
     455    ASSERT(threadID);
     456
     457    unsigned threadIdentifier = static_cast<unsigned>(threadID);
     458    HANDLE threadHandle = OpenThread(SYNCHRONIZE, FALSE, threadIdentifier);
     459    // If thread already exited, return immediately.
     460    if (!threadHandle)
     461        return WAIT_OBJECT_0;
     462
     463    DWORD joinResult = WaitForSingleObject(threadHandle, INFINITE);
     464    if (joinResult == WAIT_FAILED)
     465        LOG_ERROR("ThreadIdentifier %p was found to be deadlocked trying to quit", threadHandle);
     466
     467    CloseHandle(threadHandle);
     468
     469    return joinResult;
     470}
     471
     472PlatformThreadIdentifier currentThreadDeprecated()
     473{
     474    return static_cast<PlatformThreadIdentifier>(GetCurrentThreadId());
     475}
     476
     477PlatformThreadIdentifier createThreadDeprecated(ThreadFunction entryPoint, void* data, const char* name)
     478{
     479    ThreadIdentifier threadID = createThread(entryPoint, data, name);
     480    return static_cast<PlatformThreadIdentifier>(threadID.platformId());
     481}
     482
    473483} // namespace WTF
  • trunk/JavaScriptCore/wtf/gtk/ThreadingGtk.cpp

    r43392 r43507  
    4343namespace WTF {
    4444
     45bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
     46{
     47    return m_platformId == another.m_platformId;
     48}
     49
     50bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
     51{
     52    return m_platformId != another.m_platformId;
     53}
     54
    4555static Mutex* atomicallyInitializedStaticMutex;
    4656
    4757static ThreadIdentifier mainThreadIdentifier;
    48 
    49 static Mutex& threadMapMutex()
    50 {
    51     static Mutex mutex;
    52     return mutex;
    53 }
    5458
    5559void initializeThreading()
     
    6165    if (!atomicallyInitializedStaticMutex) {
    6266        atomicallyInitializedStaticMutex = new Mutex;
    63         threadMapMutex();
    6467        initializeRandomNumberGenerator();
    6568        mainThreadIdentifier = currentThread();
     
    7982}
    8083
    81 static HashMap<ThreadIdentifier, GThread*>& threadMap()
    82 {
    83     static HashMap<ThreadIdentifier, GThread*> map;
    84     return map;
    85 }
    86 
    87 static ThreadIdentifier identifierByGthreadHandle(GThread*& thread)
    88 {
    89     MutexLocker locker(threadMapMutex());
    90 
    91     HashMap<ThreadIdentifier, GThread*>::iterator i = threadMap().begin();
    92     for (; i != threadMap().end(); ++i) {
    93         if (i->second == thread)
    94             return i->first;
    95     }
    96 
    97     return 0;
    98 }
    99 
    100 static ThreadIdentifier establishIdentifierForThread(GThread*& thread)
    101 {
    102     ASSERT(!identifierByGthreadHandle(thread));
    103 
    104     MutexLocker locker(threadMapMutex());
    105 
    106     static ThreadIdentifier identifierCount = 1;
    107 
    108     threadMap().add(identifierCount, thread);
    109 
    110     return identifierCount++;
    111 }
    112 
    113 static GThread* threadForIdentifier(ThreadIdentifier id)
    114 {
    115     MutexLocker locker(threadMapMutex());
    116 
    117     return threadMap().get(id);
    118 }
    119 
    120 static void clearThreadForIdentifier(ThreadIdentifier id)
    121 {
    122     MutexLocker locker(threadMapMutex());
    123 
    124     ASSERT(threadMap().contains(id));
    125 
    126     threadMap().remove(id);
    127 }
    128 
    12984ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*)
    13085{
     
    13287    if (!(thread = g_thread_create(entryPoint, data, TRUE, 0))) {
    13388        LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data);
    134         return 0;
     89        return ThreadIdentifier();
    13590    }
    13691
    137     ThreadIdentifier threadID = establishIdentifierForThread(thread);
    138     return threadID;
     92    return ThreadIdentifier(thread);
    13993}
    14094
     
    14599int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    146100{
    147     ASSERT(threadID);
     101    ASSERT(threadID.isValid());
    148102
    149     GThread* thread = threadForIdentifier(threadID);
     103    GThread* thread = threadID.platformId();
    150104
    151105    void* joinResult = g_thread_join(thread);
     
    153107        *result = joinResult;
    154108
    155     clearThreadForIdentifier(threadID);
    156109    return 0;
    157110}
     
    163116ThreadIdentifier currentThread()
    164117{
    165     GThread* currentThread = g_thread_self();
    166     if (ThreadIdentifier id = identifierByGthreadHandle(currentThread))
    167         return id;
    168     return establishIdentifierForThread(currentThread);
     118    return ThreadIdentifier(g_thread_self());
    169119}
    170120
  • trunk/JavaScriptCore/wtf/qt/ThreadingQt.cpp

    r43392 r43507  
    4242namespace WTF {
    4343
     44bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
     45{
     46    return m_platformId == another.m_platformId;
     47}
     48
     49bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
     50{
     51    return m_platformId != another.m_platformId;
     52}
     53
    4454class ThreadPrivate : public QThread {
    4555public:
     
    7080static ThreadIdentifier mainThreadIdentifier;
    7181
    72 static Mutex& threadMapMutex()
    73 {
    74     static Mutex mutex;
    75     return mutex;
    76 }
    77 
    78 static HashMap<ThreadIdentifier, QThread*>& threadMap()
    79 {
    80     static HashMap<ThreadIdentifier, QThread*> map;
    81     return map;
    82 }
    83 
    84 static ThreadIdentifier identifierByQthreadHandle(QThread*& thread)
    85 {
    86     MutexLocker locker(threadMapMutex());
    87 
    88     HashMap<ThreadIdentifier, QThread*>::iterator i = threadMap().begin();
    89     for (; i != threadMap().end(); ++i) {
    90         if (i->second == thread)
    91             return i->first;
    92     }
    93 
    94     return 0;
    95 }
    96 
    97 static ThreadIdentifier establishIdentifierForThread(QThread*& thread)
    98 {
    99     ASSERT(!identifierByQthreadHandle(thread));
    100 
    101     MutexLocker locker(threadMapMutex());
    102 
    103     static ThreadIdentifier identifierCount = 1;
    104 
    105     threadMap().add(identifierCount, thread);
    106 
    107     return identifierCount++;
    108 }
    109 
    110 static void clearThreadForIdentifier(ThreadIdentifier id)
    111 {
    112     MutexLocker locker(threadMapMutex());
    113 
    114     ASSERT(threadMap().contains(id));
    115 
    116     threadMap().remove(id);
    117 }
    118 
    119 static QThread* threadForIdentifier(ThreadIdentifier id)
    120 {
    121     MutexLocker locker(threadMapMutex());
    122 
    123     return threadMap().get(id);
    124 }
    125 
    12682void initializeThreading()
    12783{
    12884    if (!atomicallyInitializedStaticMutex) {
    12985        atomicallyInitializedStaticMutex = new Mutex;
    130         threadMapMutex();
    13186        initializeRandomNumberGenerator();
    132         QThread* mainThread = QCoreApplication::instance()->thread();
    133         mainThreadIdentifier = identifierByQthreadHandle(mainThread);
    134         if (!mainThreadIdentifier)
    135             mainThreadIdentifier = establishIdentifierForThread(mainThread);
     87        mainThreadIdentifier = ThreadIdentifier(QCoreApplication::instance()->thread());
    13688        initializeMainThread();
    13789    }
     
    154106    if (!thread) {
    155107        LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data);
    156         return 0;
     108        return ThreadIdentifier();
    157109    }
    158110    thread->start();
     
    160112    QThread* threadRef = static_cast<QThread*>(thread);
    161113
    162     return establishIdentifierForThread(threadRef);
     114    return ThreadIdentifier(threadRef);
    163115}
    164116
     
    169121int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    170122{
    171     ASSERT(threadID);
    172 
    173     QThread* thread = threadForIdentifier(threadID);
     123    ASSERT(threadID.IsValid());
     124
     125    QThread* thread = threadID.platformId();
    174126
    175127    bool res = thread->wait();
    176128
    177     clearThreadForIdentifier(threadID);
    178129    if (result)
    179130        *result = static_cast<ThreadPrivate*>(thread)->getReturnValue();
     
    188139ThreadIdentifier currentThread()
    189140{
    190     QThread* currentThread = QThread::currentThread();
    191     if (ThreadIdentifier id = identifierByQthreadHandle(currentThread))
    192         return id;
    193     return establishIdentifierForThread(currentThread);
     141    return ThreadIdentifier(QThread::currentThread());
    194142}
    195143
  • trunk/WebCore/ChangeLog

    r43503 r43507  
     12009-05-11  Dmitry Titov  <[email protected]>
     2
     3        Reviewed by Alexey Proskuryakov and Adam Roben.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=25348
     6        Change WTF::ThreadIdentifier to be an actual (but wrapped) thread id, remove ThreadMap.
     7
     8        Most of the change is in WTF.
     9        Unless noted, all the following files changed to use the new ThreadIdentifier::isValid()
     10        method instead of just doing 'if(m_threadID)' kind of checks, since ThreadIdentifier
     11        is now a class rather then an integer.
     12        Also, there is no need to initialize threadID in constructors to 0 now.
     13
     14        * dom/XMLTokenizerLibxml2.cpp:
     15        (WebCore::libxmlLoaderThread): use DEFINE_STATIC_LOCAL and accessor function for static thread id,
     16        since now ThreadIdentifier needs construction and we avoid having global initializers.
     17        (WebCore::matchFunc): use the new accessor function.
     18        (WebCore::openFunc): ditto.
     19        (WebCore::createStringParser): ditto.
     20        (WebCore::createMemoryParser): ditto.
     21        * loader/icon/IconDatabase.cpp:
     22        (WebCore::IconDatabase::open):
     23        * platform/sql/SQLiteDatabase.cpp:
     24        (WebCore::SQLiteDatabase::SQLiteDatabase):
     25        (WebCore::SQLiteDatabase::close):
     26        * storage/DatabaseThread.cpp:
     27        (WebCore::DatabaseThread::start):
     28        (WebCore::DatabaseThread::databaseThread): remove m_threadID from debug output.
     29        * storage/LocalStorageThread.cpp:
     30        (WebCore::LocalStorageThread::start):
     31        (WebCore::LocalStorageThread::scheduleImport):
     32        (WebCore::LocalStorageThread::scheduleSync):
     33        (WebCore::LocalStorageThread::terminate):
     34        * workers/WorkerThread.cpp:
     35        (WebCore::WorkerThread::start):
     36        (WebCore::WorkerThread::WorkerThread):
     37        (WebCore::WorkerThread::start):
     38
    1392009-05-11  Brady Eidson  <[email protected]>
    240
  • trunk/WebCore/dom/XMLTokenizerLibxml2.cpp

    r43392 r43507  
    327327
    328328static int globalDescriptor = 0;
    329 static ThreadIdentifier libxmlLoaderThread = 0;
     329
     330static ThreadIdentifier& libxmlLoaderThread() {
     331    DEFINE_STATIC_LOCAL(ThreadIdentifier, staticLibxmlLoaderThread, ());
     332    return staticLibxmlLoaderThread;
     333}
    330334
    331335static int matchFunc(const char*)
     
    333337    // Only match loads initiated due to uses of libxml2 from within XMLTokenizer to avoid
    334338    // interfering with client applications that also use libxml2.  http://bugs.webkit.org/show_bug.cgi?id=17353
    335     return XMLTokenizerScope::currentDocLoader && currentThread() == libxmlLoaderThread;
     339    return XMLTokenizerScope::currentDocLoader && currentThread() == libxmlLoaderThread();
    336340}
    337341
     
    394398{
    395399    ASSERT(XMLTokenizerScope::currentDocLoader);
    396     ASSERT(currentThread() == libxmlLoaderThread);
     400    ASSERT(currentThread() == libxmlLoaderThread());
    397401
    398402    KURL url(KURL(), uri);
     
    463467        xmlRegisterInputCallbacks(matchFunc, openFunc, readFunc, closeFunc);
    464468        xmlRegisterOutputCallbacks(matchFunc, openFunc, writeFunc, closeFunc);
    465         libxmlLoaderThread = currentThread();
     469        libxmlLoaderThread() = currentThread();
    466470        didInit = true;
    467471    }
     
    485489        xmlRegisterInputCallbacks(matchFunc, openFunc, readFunc, closeFunc);
    486490        xmlRegisterOutputCallbacks(matchFunc, openFunc, writeFunc, closeFunc);
    487         libxmlLoaderThread = currentThread();
     491        libxmlLoaderThread() = currentThread();
    488492        didInit = true;
    489493    }
  • trunk/WebCore/loader/icon/IconDatabase.cpp

    r43392 r43507  
    136136    m_syncLock.lock();
    137137    m_syncThread = createThread(IconDatabase::iconDatabaseSyncThreadStart, this, "WebCore: IconDatabase");
    138     m_syncThreadRunning = m_syncThread;
     138    m_syncThreadRunning = m_syncThread.isValid();
    139139    m_syncLock.unlock();
    140     if (!m_syncThread)
    141         return false;
    142     return true;
     140
     141    return m_syncThreadRunning;
    143142}
    144143
  • trunk/WebCore/platform/sql/SQLiteDatabase.cpp

    r43392 r43507  
    4848    , m_pageSize(-1)
    4949    , m_transactionInProgress(false)
    50     , m_openingThread(0)
    5150{
    5251}
     
    9089    }
    9190
    92     m_openingThread = 0;
     91    m_openingThread.invalidate();
    9392}
    9493
  • trunk/WebCore/storage/DatabaseThread.cpp

    r43392 r43507  
    4040
    4141DatabaseThread::DatabaseThread()
    42     : m_threadID(0)
    4342{
    4443    m_selfRef = this;
     
    5453    MutexLocker lock(m_threadCreationMutex);
    5554
    56     if (m_threadID)
     55    if (m_threadID.isValid())
    5756        return true;
    5857
    5958    m_threadID = createThread(DatabaseThread::databaseThreadStart, this, "WebCore: Database");
    6059
    61     return m_threadID;
     60    return m_threadID.isValid();
    6261}
    6362
     
    9897    }
    9998
    100     LOG(StorageAPI, "About to detach thread %i and clear the ref to DatabaseThread %p, which currently has %i ref(s)", m_threadID, this, refCount());
     99    LOG(StorageAPI, "About to detach thread and clear the ref to DatabaseThread %p, which currently has %i ref(s)", this, refCount());
    101100
    102101    // Detach the thread so its resources are no longer of any concern to anyone else
  • trunk/WebCore/storage/LocalStorageThread.cpp

    r43392 r43507  
    3939
    4040LocalStorageThread::LocalStorageThread()
    41     : m_threadID(0)
    4241{
    4342    m_selfRef = this;
     
    4847    MutexLocker lock(m_threadCreationMutex);
    4948
    50     if (m_threadID)
    51         return true;
     49    if (!m_threadID.isValid())
     50        m_threadID = createThread(LocalStorageThread::localStorageThreadStart, this, "WebCore: LocalStorage");
    5251
    53     m_threadID = createThread(LocalStorageThread::localStorageThreadStart, this, "WebCore: LocalStorage");
    54 
    55     return m_threadID;
     52    return m_threadID.isValid();
    5653}
    5754
     
    7875    // Detach the thread so its resources are no longer of any concern to anyone else
    7976    detachThread(m_threadID);
    80     m_threadID = 0;
     77    m_threadID.invalidate();
    8178
    8279    // Clear the self refptr, possibly resulting in deletion
     
    8885void LocalStorageThread::scheduleImport(PassRefPtr<LocalStorage> storage)
    8986{
    90     ASSERT(!m_queue.killed() && m_threadID);
     87    ASSERT(!m_queue.killed() && m_threadID.isValid());
    9188    m_queue.append(LocalStorageTask::createImport(storage));
    9289}
     
    9491void LocalStorageThread::scheduleSync(PassRefPtr<LocalStorage> storage)
    9592{
    96     ASSERT(!m_queue.killed() && m_threadID);
     93    ASSERT(!m_queue.killed() && m_threadID.isValid());
    9794    m_queue.append(LocalStorageTask::createSync(storage));
    9895}
     
    10097void LocalStorageThread::scheduleImport(PassRefPtr<LocalStorageArea> area)
    10198{
    102     ASSERT(!m_queue.killed() && m_threadID);
     99    ASSERT(!m_queue.killed() && m_threadID.isValid());
    103100    m_queue.append(LocalStorageTask::createImport(area));
    104101}
     
    106103void LocalStorageThread::scheduleSync(PassRefPtr<LocalStorageArea> area)
    107104{
    108     ASSERT(!m_queue.killed() && m_threadID);
     105    ASSERT(!m_queue.killed() && m_threadID.isValid());
    109106    m_queue.append(LocalStorageTask::createSync(area));
    110107}
     
    116113    // Ideally we'd never be killing a thread that wasn't live, so ASSERT it.
    117114    // But if we do in a release build, make sure to not wait on a condition that will never get signalled
    118     ASSERT(!m_queue.killed() && m_threadID);
    119     if (!m_threadID)
     115    ASSERT(!m_queue.killed() && m_threadID.isValid());
     116    if (!m_threadID.isValid())
    120117        return;
    121118
  • trunk/WebCore/workers/WorkerThread.cpp

    r43392 r43507  
    6969
    7070WorkerThread::WorkerThread(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerObjectProxy* workerObjectProxy)
    71     : m_threadID(0)
    72     , m_workerObjectProxy(workerObjectProxy)
     71    : m_workerObjectProxy(workerObjectProxy)
    7372    , m_startupData(WorkerThreadStartupData::create(scriptURL, userAgent, sourceCode))
    7473{
     
    8483    MutexLocker lock(m_threadCreationMutex);
    8584
    86     if (m_threadID)
    87         return true;
     85    if (!m_threadID.isValid())
     86        m_threadID = createThread(WorkerThread::workerThreadStart, this, "WebCore: Worker");
    8887
    89     m_threadID = createThread(WorkerThread::workerThreadStart, this, "WebCore: Worker");
    90 
    91     return m_threadID;
     88    return m_threadID.isValid();
    9289}
    9390
  • trunk/WebKit/win/ChangeLog

    r43460 r43507  
     12009-05-11  Dmitry Titov  <[email protected]>
     2
     3        Reviewed by Alexey Proskuryakov and Adam Roben.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=25348
     6        Change WTF::ThreadIdentifier to be an actual (but wrapped) thread id, remove ThreadMap.
     7
     8        Most of the change is in WTF and WebCore.
     9
     10        * WebKit.vcproj/WebKit.def: replaced decorated names of WTF threading functions with new ones.
     11        Also, aliased the old implementations so the public Safari 4 beta can load the old WTF functions
     12        which it uses. Next time Safari 4 builds, it will pick up new functions and the deprecated ones
     13        can be removed.
     14        * WebKit.vcproj/WebKit_debug.def: same.
     15
    1162009-05-10  Alexey Proskuryakov  <[email protected]>
    217
  • trunk/WebKit/win/WebKit.vcproj/WebKit.def

    r43392 r43507  
    115115        ??1Mutex@WTF@@QAE@XZ
    116116        ??1ThreadCondition@WTF@@QAE@XZ
     117        ??8ThreadIdentifier@WTF@@QBE_NABV01@@Z
    117118        ?broadcast@ThreadCondition@WTF@@QAEXXZ
    118119        ?callOnMainThread@WTF@@YAXP6AXPAX@Z0@Z
    119         ?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z
    120         ?currentThread@WTF@@YAIXZ
    121         ?detachThread@WTF@@YAXI@Z
     120        ?createThread@WTF@@YA?AVThreadIdentifier@1@P6APAXPAX@Z0PBD@Z
     121        ?currentThread@WTF@@YA?AVThreadIdentifier@1@XZ
     122        ?detachThread@WTF@@YAXVThreadIdentifier@1@@Z
    122123        ?initializeMainThread@WTF@@YAXXZ
    123124        ?initializeThreading@WTF@@YAXXZ
     
    133134        ?unlockAtomicallyInitializedStaticMutex@WTF@@YAXXZ
    134135        ?wait@ThreadCondition@WTF@@QAEXAAVMutex@2@@Z
    135         ?waitForThreadCompletion@WTF@@YAHIPAPAX@Z
    136         ?createThread@WTF@@YAIP6APAXPAX@Z0@Z
     136        ?waitForThreadCompletion@WTF@@YAHVThreadIdentifier@1@PAPAX@Z
     137        ?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z=?createThreadDeprecated@WTF@@YAIP6APAXPAX@Z0PBD@Z
     138        ?currentThread@WTF@@YAIXZ=?currentThreadDeprecated@WTF@@YAIXZ
     139        ?detachThread@WTF@@YAXI@Z=?detachThreadDeprecated@WTF@@YAXI@Z
     140        ?waitForThreadCompletion@WTF@@YAHIPAPAX@Z=?waitForThreadCompletionDeprecated@WTF@@YAHIPAPAX@Z
  • trunk/WebKit/win/WebKit.vcproj/WebKit_debug.def

    r43392 r43507  
    115115        ??1Mutex@WTF@@QAE@XZ
    116116        ??1ThreadCondition@WTF@@QAE@XZ
     117        ??8ThreadIdentifier@WTF@@QBE_NABV01@@Z
    117118        ?broadcast@ThreadCondition@WTF@@QAEXXZ
    118119        ?callOnMainThread@WTF@@YAXP6AXPAX@Z0@Z
    119         ?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z
    120         ?currentThread@WTF@@YAIXZ
    121         ?detachThread@WTF@@YAXI@Z
     120        ?createThread@WTF@@YA?AVThreadIdentifier@1@P6APAXPAX@Z0PBD@Z
     121        ?currentThread@WTF@@YA?AVThreadIdentifier@1@XZ
     122        ?detachThread@WTF@@YAXVThreadIdentifier@1@@Z
    122123        ?initializeMainThread@WTF@@YAXXZ
    123124        ?initializeThreading@WTF@@YAXXZ
     
    133134        ?unlockAtomicallyInitializedStaticMutex@WTF@@YAXXZ
    134135        ?wait@ThreadCondition@WTF@@QAEXAAVMutex@2@@Z
    135         ?waitForThreadCompletion@WTF@@YAHIPAPAX@Z
    136         ?createThread@WTF@@YAIP6APAXPAX@Z0@Z
     136        ?waitForThreadCompletion@WTF@@YAHVThreadIdentifier@1@PAPAX@Z
     137        ?createThread@WTF@@YAIP6APAXPAX@Z0PBD@Z=?createThreadDeprecated@WTF@@YAIP6APAXPAX@Z0PBD@Z
     138        ?currentThread@WTF@@YAIXZ=?currentThreadDeprecated@WTF@@YAIXZ
     139        ?detachThread@WTF@@YAXI@Z=?detachThreadDeprecated@WTF@@YAXI@Z
     140        ?waitForThreadCompletion@WTF@@YAHIPAPAX@Z=?waitForThreadCompletionDeprecated@WTF@@YAHIPAPAX@Z
Note: See TracChangeset for help on using the changeset viewer.