Ignore:
Timestamp:
May 7, 2009, 2:24:36 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-05-07 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.

  • 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/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 the WTF threading functions decorated names 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-07 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-07 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/qt/ThreadingQt.cpp

    r42858 r43366  
    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
Note: See TracChangeset for help on using the changeset viewer.