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