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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.