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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.