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/Threading.h

    r41605 r43366  
    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// The only way to obtain a valid ThreadIdentifier is 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:
Note: See TracChangeset for help on using the changeset viewer.