Changeset 43392 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
May 7, 2009, 11:47:19 PM (16 years ago)
Author:
[email protected]
Message:

Fix <https://bugs.webkit.org/show_bug.cgi?id=25640>.
Bug 25640: Crash on quit in r43384 nightly build on Leopard w/ Safari 4 beta installed

Rubber-stamped by Oliver Hunt.

Roll out r43366 as it removed symbols that Safari 4 Beta uses.

Location:
trunk/JavaScriptCore/wtf
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/CrossThreadRefCounted.h

    r43366 r43392  
    7575            : m_threadSafeRefCounter(threadedCounter)
    7676            , m_data(data)
     77#ifndef NDEBUG
     78            , m_threadId(0)
     79#endif
    7780        {
    7881        }
     
    97100    void CrossThreadRefCounted<T>::ref()
    98101    {
    99         ASSERT(!m_threadId.isValid() || m_threadId == currentThread());
     102        ASSERT(!m_threadId || m_threadId == currentThread());
    100103        m_refCounter.ref();
    101104#ifndef NDEBUG
     
    105108        // is a heuristic but it seems to always work and has helped
    106109        // find some bugs.
    107         if (!m_threadId.isValid() && m_refCounter.refCount() == 2)
     110        if (!m_threadId && m_refCounter.refCount() == 2)
    108111            m_threadId = currentThread();
    109112#endif
     
    113116    void CrossThreadRefCounted<T>::deref()
    114117    {
    115         ASSERT(!m_threadId.isValid() || m_threadId == currentThread());
     118        ASSERT(!m_threadId || m_threadId == currentThread());
    116119        if (m_refCounter.derefBase()) {
    117120            threadSafeDeref();
     
    122125            // is safe to be passed to another thread at this point.
    123126            if (m_threadId && m_refCounter.refCount() == 1)
    124                 m_threadId.invalidate();
     127                m_threadId = 0;
    125128#endif
    126129        }
  • trunk/JavaScriptCore/wtf/Threading.h

    r43366 r43392  
    8686typedef struct _GMutex GMutex;
    8787typedef struct _GCond GCond;
    88 typedef struct _GThread GThread;
    8988#endif
    9089
     
    9392QT_BEGIN_NAMESPACE
    9493class QMutex;
    95 class QThread;
    9694class QWaitCondition;
    9795QT_END_NAMESPACE
     
    108106namespace WTF {
    109107
     108typedef uint32_t ThreadIdentifier;
     109typedef 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.
     113ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
     114
     115// Internal platform-specific createThread implementation.
     116ThreadIdentifier 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.
     120void setThreadNameInternal(const char* threadName);
     121
     122ThreadIdentifier currentThread();
     123bool isMainThread();
     124int waitForThreadCompletion(ThreadIdentifier, void**);
     125void detachThread(ThreadIdentifier);
     126
    110127#if USE(PTHREADS)
    111128typedef pthread_mutex_t PlatformMutex;
    112129typedef pthread_cond_t PlatformCondition;
    113 typedef pthread_t PlatformThreadIdentifier;
    114130#elif PLATFORM(GTK)
    115131typedef GOwnPtr<GMutex> PlatformMutex;
    116132typedef GOwnPtr<GCond> PlatformCondition;
    117 typedef GThread* PlatformThreadIdentifier;
    118133#elif PLATFORM(QT)
    119134typedef QT_PREPEND_NAMESPACE(QMutex)* PlatformMutex;
    120135typedef QT_PREPEND_NAMESPACE(QWaitCondition)* PlatformCondition;
    121 typedef QT_PREPEND_NAMESPACE(QThread)* PlatformThreadIdentifier;
    122136#elif PLATFORM(WIN_OS)
    123137struct PlatformMutex {
     
    136150    void signal(bool unblockAll);
    137151};
    138 typedef unsigned PlatformThreadIdentifier;
    139152#else
    140153typedef void* PlatformMutex;
     
    142155#endif
    143156   
    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.
    149 class ThreadIdentifier {
    150 public:
    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 
    171 private:
    172     PlatformThreadIdentifier m_platformId;
    173 };
    174 
    175 typedef 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.
    179 ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
    180 
    181 // Internal platform-specific createThread implementation.
    182 ThreadIdentifier 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.
    186 void setThreadNameInternal(const char* threadName);
    187 
    188 ThreadIdentifier currentThread();
    189 bool isMainThread();
    190 int waitForThreadCompletion(ThreadIdentifier, void**);
    191 void detachThread(ThreadIdentifier);
    192 
    193157class Mutex : Noncopyable {
    194158public:
  • trunk/JavaScriptCore/wtf/ThreadingNone.cpp

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

    r43366 r43392  
    4949namespace WTF {
    5050
    51 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
    52 {
    53     return pthread_equal(m_platformId, another.m_platformId);
    54 }
    55 
    56 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
    57 {
    58     return !pthread_equal(m_platformId, another.m_platformId);
    59 }
     51typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap;
    6052
    6153static Mutex* atomicallyInitializedStaticMutex;
     
    6557#endif
    6658
     59static Mutex& threadMapMutex()
     60{
     61    DEFINE_STATIC_LOCAL(Mutex, mutex, ());
     62    return mutex;
     63}
     64
    6765void initializeThreading()
    6866{
    6967    if (!atomicallyInitializedStaticMutex) {
    7068        atomicallyInitializedStaticMutex = new Mutex;
     69        threadMapMutex();
    7170        initializeRandomNumberGenerator();
    7271#if !PLATFORM(DARWIN) || PLATFORM(CHROMIUM)
     
    8685{
    8786    atomicallyInitializedStaticMutex->unlock();
     87}
     88
     89static ThreadMap& threadMap()
     90{
     91    DEFINE_STATIC_LOCAL(ThreadMap, map, ());
     92    return map;
     93}
     94
     95static 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
     108static 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
     121static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id)
     122{
     123    MutexLocker locker(threadMapMutex());
     124   
     125    return threadMap().get(id);
     126}
     127
     128static void clearPthreadHandleForIdentifier(ThreadIdentifier id)
     129{
     130    MutexLocker locker(threadMapMutex());
     131
     132    ASSERT(threadMap().contains(id));
     133   
     134    threadMap().remove(id);
    88135}
    89136
     
    118165    if (pthread_create(&threadHandle, 0, runThreadWithRegistration, static_cast<void*>(threadData))) {
    119166        LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
    120         return ThreadIdentifier();
    121     }
    122     return ThreadIdentifier(threadHandle);
     167        return 0;
     168    }
     169    return establishIdentifierForPthreadHandle(threadHandle);
    123170}
    124171#else
     
    128175    if (pthread_create(&threadHandle, 0, entryPoint, data)) {
    129176        LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
    130         return ThreadIdentifier();
    131     }
    132 
    133     return ThreadIdentifier(threadHandle);
     177        return 0;
     178    }
     179
     180    return establishIdentifierForPthreadHandle(threadHandle);
    134181}
    135182#endif
     
    146193int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    147194{
    148     ASSERT(threadID.isValid());
    149    
    150     pthread_t pthreadHandle = threadID.platformId();
     195    ASSERT(threadID);
     196   
     197    pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID);
    151198 
    152199    int joinResult = pthread_join(pthreadHandle, result);
    153200    if (joinResult == EDEADLK)
    154         LOG_ERROR("ThreadIdentifier %p was found to be deadlocked trying to quit", pthreadHandle);
     201        LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID);
    155202       
     203    clearPthreadHandleForIdentifier(threadID);
    156204    return joinResult;
    157205}
     
    159207void detachThread(ThreadIdentifier threadID)
    160208{
    161     ASSERT(threadID.isValid());
    162    
    163     pthread_t pthreadHandle = threadID.platformId();
     209    ASSERT(threadID);
     210   
     211    pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID);
    164212   
    165213    pthread_detach(pthreadHandle);
     214   
     215    clearPthreadHandleForIdentifier(threadID);
    166216}
    167217
    168218ThreadIdentifier currentThread()
    169219{
    170     return ThreadIdentifier(pthread_self());
     220    pthread_t currentThread = pthread_self();
     221    if (ThreadIdentifier id = identifierByPthreadHandle(currentThread))
     222        return id;
     223    return establishIdentifierForPthreadHandle(currentThread);
    171224}
    172225
  • trunk/JavaScriptCore/wtf/ThreadingWin.cpp

    r43366 r43392  
    9999namespace WTF {
    100100
    101 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
    102 {
    103     return m_platformId == another.m_platformId;
    104 }
    105 
    106 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
    107 {
    108     return m_platformId != another.m_platformId;
    109 }
    110 
    111101// MS_VC_EXCEPTION, THREADNAME_INFO, and setThreadNameInternal all come from <http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>.
    112102static const DWORD MS_VC_EXCEPTION = 0x406D1388;
     
    150140static ThreadIdentifier mainThreadIdentifier;
    151141
     142static Mutex& threadMapMutex()
     143{
     144    static Mutex mutex;
     145    return mutex;
     146}
     147
    152148void initializeThreading()
    153149{
    154150    if (!atomicallyInitializedStaticMutex) {
    155151        atomicallyInitializedStaticMutex = new Mutex;
     152        threadMapMutex();
    156153        initializeRandomNumberGenerator();
    157154        initializeMainThread();
     
    161158}
    162159
     160static HashMap<DWORD, HANDLE>& threadMap()
     161{
     162    static HashMap<DWORD, HANDLE> map;
     163    return map;
     164}
     165
     166static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle)
     167{
     168    MutexLocker locker(threadMapMutex());
     169    ASSERT(!threadMap().contains(threadID));
     170    threadMap().add(threadID, threadHandle);
     171}
     172
     173static HANDLE threadHandleForIdentifier(ThreadIdentifier id)
     174{
     175    MutexLocker locker(threadMapMutex());
     176    return threadMap().get(id);
     177}
     178
     179static void clearThreadHandleForIdentifier(ThreadIdentifier id)
     180{
     181    MutexLocker locker(threadMapMutex());
     182    ASSERT(threadMap().contains(id));
     183    threadMap().remove(id);
     184}
     185
    163186struct ThreadFunctionInvocation {
    164187    ThreadFunctionInvocation(ThreadFunction function, void* data) : function(function), data(data) {}
     
    186209{
    187210    unsigned threadIdentifier = 0;
     211    ThreadIdentifier threadID = 0;
    188212    ThreadFunctionInvocation* invocation = new ThreadFunctionInvocation(entryPoint, data);
    189213    HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThreadEntryPoint, invocation, 0, &threadIdentifier));
    190214    if (!threadHandle) {
    191215        LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld", entryPoint, data, errno);
    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);
     216        return 0;
     217    }
     218
     219    threadID = static_cast<ThreadIdentifier>(threadIdentifier);
     220    storeThreadHandleByIdentifier(threadIdentifier, threadHandle);
     221
     222    return threadID;
    198223}
    199224
    200225int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    201226{
    202     ASSERT(threadID.isValid());
     227    ASSERT(threadID);
    203228   
    204     unsigned threadIdentifier = threadID.platformId();
    205     HANDLE threadHandle = OpenThread(SYNCHRONIZE, FALSE, threadIdentifier);
    206     // If thread already exited, return immediately.
     229    HANDLE threadHandle = threadHandleForIdentifier(threadID);
    207230    if (!threadHandle)
    208         return WAIT_OBJECT_0;
     231        LOG_ERROR("ThreadIdentifier %u did not correspond to an active thread when trying to quit", threadID);
    209232 
    210233    DWORD joinResult = WaitForSingleObject(threadHandle, INFINITE);
    211234    if (joinResult == WAIT_FAILED)
    212         LOG_ERROR("ThreadIdentifier %p was found to be deadlocked trying to quit", threadHandle);
     235        LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID);
    213236
    214237    CloseHandle(threadHandle);
     238    clearThreadHandleForIdentifier(threadID);
    215239
    216240    return joinResult;
    217241}
    218242
    219 void detachThread(ThreadIdentifier)
    220 {
     243void detachThread(ThreadIdentifier threadID)
     244{
     245    ASSERT(threadID);
     246   
     247    HANDLE threadHandle = threadHandleForIdentifier(threadID);
     248    if (threadHandle)
     249        CloseHandle(threadHandle);
     250    clearThreadHandleForIdentifier(threadID);
    221251}
    222252
    223253ThreadIdentifier currentThread()
    224254{
    225     return ThreadIdentifier(GetCurrentThreadId());
     255    return static_cast<ThreadIdentifier>(GetCurrentThreadId());
    226256}
    227257
     
    441471}
    442472
    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.
    449 void detachThreadDeprecated(PlatformThreadIdentifier)
    450 {
    451 }
    452 
    453 int 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 
    472 PlatformThreadIdentifier currentThreadDeprecated()
    473 {
    474     return static_cast<PlatformThreadIdentifier>(GetCurrentThreadId());
    475 }
    476 
    477 PlatformThreadIdentifier 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 
    483473} // namespace WTF
  • trunk/JavaScriptCore/wtf/gtk/ThreadingGtk.cpp

    r43366 r43392  
    4343namespace WTF {
    4444
    45 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
    46 {
    47     return m_platformId == another.m_platformId;
    48 }
    49 
    50 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
    51 {
    52     return m_platformId != another.m_platformId;
    53 }
    54 
    5545static Mutex* atomicallyInitializedStaticMutex;
    5646
    5747static ThreadIdentifier mainThreadIdentifier;
     48
     49static Mutex& threadMapMutex()
     50{
     51    static Mutex mutex;
     52    return mutex;
     53}
    5854
    5955void initializeThreading()
     
    6561    if (!atomicallyInitializedStaticMutex) {
    6662        atomicallyInitializedStaticMutex = new Mutex;
     63        threadMapMutex();
    6764        initializeRandomNumberGenerator();
    6865        mainThreadIdentifier = currentThread();
     
    8279}
    8380
     81static HashMap<ThreadIdentifier, GThread*>& threadMap()
     82{
     83    static HashMap<ThreadIdentifier, GThread*> map;
     84    return map;
     85}
     86
     87static 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
     100static 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
     113static GThread* threadForIdentifier(ThreadIdentifier id)
     114{
     115    MutexLocker locker(threadMapMutex());
     116
     117    return threadMap().get(id);
     118}
     119
     120static void clearThreadForIdentifier(ThreadIdentifier id)
     121{
     122    MutexLocker locker(threadMapMutex());
     123
     124    ASSERT(threadMap().contains(id));
     125
     126    threadMap().remove(id);
     127}
     128
    84129ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*)
    85130{
     
    87132    if (!(thread = g_thread_create(entryPoint, data, TRUE, 0))) {
    88133        LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data);
    89         return ThreadIdentifier();
    90     }
    91 
    92     return ThreadIdentifier(thread);
     134        return 0;
     135    }
     136
     137    ThreadIdentifier threadID = establishIdentifierForThread(thread);
     138    return threadID;
    93139}
    94140
     
    99145int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    100146{
    101     ASSERT(threadID.isValid());
    102 
    103     GThread* thread = threadID.platformId();
     147    ASSERT(threadID);
     148
     149    GThread* thread = threadForIdentifier(threadID);
    104150
    105151    void* joinResult = g_thread_join(thread);
     
    107153        *result = joinResult;
    108154
     155    clearThreadForIdentifier(threadID);
    109156    return 0;
    110157}
     
    116163ThreadIdentifier currentThread()
    117164{
    118     return ThreadIdentifier(g_thread_self());
     165    GThread* currentThread = g_thread_self();
     166    if (ThreadIdentifier id = identifierByGthreadHandle(currentThread))
     167        return id;
     168    return establishIdentifierForThread(currentThread);
    119169}
    120170
  • trunk/JavaScriptCore/wtf/qt/ThreadingQt.cpp

    r43366 r43392  
    4242namespace WTF {
    4343
    44 bool ThreadIdentifier::operator==(const ThreadIdentifier& another) const
    45 {
    46     return m_platformId == another.m_platformId;
    47 }
    48 
    49 bool ThreadIdentifier::operator!=(const ThreadIdentifier& another) const
    50 {
    51     return m_platformId != another.m_platformId;
    52 }
    53 
    5444class ThreadPrivate : public QThread {
    5545public:
     
    8070static ThreadIdentifier mainThreadIdentifier;
    8171
     72static Mutex& threadMapMutex()
     73{
     74    static Mutex mutex;
     75    return mutex;
     76}
     77
     78static HashMap<ThreadIdentifier, QThread*>& threadMap()
     79{
     80    static HashMap<ThreadIdentifier, QThread*> map;
     81    return map;
     82}
     83
     84static 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
     97static 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
     110static void clearThreadForIdentifier(ThreadIdentifier id)
     111{
     112    MutexLocker locker(threadMapMutex());
     113
     114    ASSERT(threadMap().contains(id));
     115
     116    threadMap().remove(id);
     117}
     118
     119static QThread* threadForIdentifier(ThreadIdentifier id)
     120{
     121    MutexLocker locker(threadMapMutex());
     122
     123    return threadMap().get(id);
     124}
     125
    82126void initializeThreading()
    83127{
    84128    if (!atomicallyInitializedStaticMutex) {
    85129        atomicallyInitializedStaticMutex = new Mutex;
     130        threadMapMutex();
    86131        initializeRandomNumberGenerator();
    87         mainThreadIdentifier = ThreadIdentifier(QCoreApplication::instance()->thread());
     132        QThread* mainThread = QCoreApplication::instance()->thread();
     133        mainThreadIdentifier = identifierByQthreadHandle(mainThread);
     134        if (!mainThreadIdentifier)
     135            mainThreadIdentifier = establishIdentifierForThread(mainThread);
    88136        initializeMainThread();
    89137    }
     
    106154    if (!thread) {
    107155        LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data);
    108         return ThreadIdentifier();
     156        return 0;
    109157    }
    110158    thread->start();
     
    112160    QThread* threadRef = static_cast<QThread*>(thread);
    113161
    114     return ThreadIdentifier(threadRef);
     162    return establishIdentifierForThread(threadRef);
    115163}
    116164
     
    121169int waitForThreadCompletion(ThreadIdentifier threadID, void** result)
    122170{
    123     ASSERT(threadID.IsValid());
    124 
    125     QThread* thread = threadID.platformId();
     171    ASSERT(threadID);
     172
     173    QThread* thread = threadForIdentifier(threadID);
    126174
    127175    bool res = thread->wait();
    128176
     177    clearThreadForIdentifier(threadID);
    129178    if (result)
    130179        *result = static_cast<ThreadPrivate*>(thread)->getReturnValue();
     
    139188ThreadIdentifier currentThread()
    140189{
    141     return ThreadIdentifier(QThread::currentThread());
     190    QThread* currentThread = QThread::currentThread();
     191    if (ThreadIdentifier id = identifierByQthreadHandle(currentThread))
     192        return id;
     193    return establishIdentifierForThread(currentThread);
    142194}
    143195
Note: See TracChangeset for help on using the changeset viewer.