Changeset 55234 in webkit


Ignore:
Timestamp:
Feb 25, 2010, 6:49:12 AM (15 years ago)
Author:
eric@webkit.org
Message:

2010-02-25 Jochen Eisinger <jochen@chromium.org>

Reviewed by Jeremy Orlow.

Make the context that was passed to the ThreadFunction accessible.
https://bugs.webkit.org/show_bug.cgi?id=35379

  • wtf/Threading.h:
  • wtf/ThreadingNone.cpp: (WTF::threadContext):
  • wtf/ThreadingPthreads.cpp: (WTF::): (WTF::identifierByPthreadHandle): (WTF::establishIdentifierForPthreadHandle): (WTF::pthreadHandleForIdentifier): (WTF::contextForIdentifier): (WTF::createThreadInternal): (WTF::currentThread): (WTF::threadContext):
  • wtf/ThreadingWin.cpp: (WTF::): (WTF::threadMap): (WTF::storeThreadHandleByIdentifier): (WTF::threadHandleForIdentifier): (WTF::contextForIdentifier): (WTF::createThreadInternal): (WTF::threadContext):
Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r55198 r55234  
     12010-02-25  Jochen Eisinger  <jochen@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        Make the context that was passed to the ThreadFunction accessible.
     6        https://bugs.webkit.org/show_bug.cgi?id=35379
     7
     8        * wtf/Threading.h:
     9        * wtf/ThreadingNone.cpp:
     10        (WTF::threadContext):
     11        * wtf/ThreadingPthreads.cpp:
     12        (WTF::):
     13        (WTF::identifierByPthreadHandle):
     14        (WTF::establishIdentifierForPthreadHandle):
     15        (WTF::pthreadHandleForIdentifier):
     16        (WTF::contextForIdentifier):
     17        (WTF::createThreadInternal):
     18        (WTF::currentThread):
     19        (WTF::threadContext):
     20        * wtf/ThreadingWin.cpp:
     21        (WTF::):
     22        (WTF::threadMap):
     23        (WTF::storeThreadHandleByIdentifier):
     24        (WTF::threadHandleForIdentifier):
     25        (WTF::contextForIdentifier):
     26        (WTF::createThreadInternal):
     27        (WTF::threadContext):
     28
    1292010-02-24  Oliver Hunt  <oliver@apple.com>
    230
  • trunk/JavaScriptCore/wtf/Threading.h

    r55158 r55234  
    128128int waitForThreadCompletion(ThreadIdentifier, void**);
    129129void detachThread(ThreadIdentifier);
     130void* threadContext(ThreadIdentifier);
    130131
    131132#if USE(PTHREADS)
  • trunk/JavaScriptCore/wtf/ThreadingNone.cpp

    r53714 r55234  
    4242ThreadIdentifier currentThread() { return ThreadIdentifier(); }
    4343bool isMainThread() { return true; }
     44void* threadContext(ThreadIdentifier) { return 0; }
    4445
    4546Mutex::Mutex() { }
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r53815 r55234  
    5454namespace WTF {
    5555
    56 typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap;
     56typedef struct {
     57    pthread_t handle;
     58    void* context;
     59} ThreadInfo;
     60
     61typedef HashMap<ThreadIdentifier, ThreadInfo> ThreadMap;
    5762
    5863static Mutex* atomicallyInitializedStaticMutex;
     
    106111    ThreadMap::iterator i = threadMap().begin();
    107112    for (; i != threadMap().end(); ++i) {
    108         if (pthread_equal(i->second, pthreadHandle))
     113        if (pthread_equal(i->second.handle, pthreadHandle))
    109114            return i->first;
    110115    }
     
    113118}
    114119
    115 static ThreadIdentifier establishIdentifierForPthreadHandle(const pthread_t& pthreadHandle)
     120static ThreadIdentifier establishIdentifierForPthreadHandle(const pthread_t& pthreadHandle, void* context)
    116121{
    117122    ASSERT(!identifierByPthreadHandle(pthreadHandle));
     
    121126    static ThreadIdentifier identifierCount = 1;
    122127
    123     threadMap().add(identifierCount, pthreadHandle);
     128    ThreadInfo info;
     129    info.handle = pthreadHandle;
     130    info.context = context;
     131    threadMap().add(identifierCount, info);
    124132
    125133    return identifierCount++;
     
    130138    MutexLocker locker(threadMapMutex());
    131139
    132     return threadMap().get(id);
    133 }
     140    return threadMap().get(id).handle;
     141}
     142
     143static void* contextForIdentifier(ThreadIdentifier id)
     144{
     145    MutexLocker locker(threadMapMutex());
     146
     147    return threadMap().get(id).context;
     148}
     149
    134150
    135151void clearPthreadHandleForIdentifier(ThreadIdentifier id)
     
    175191        return 0;
    176192    }
    177     return establishIdentifierForPthreadHandle(threadHandle);
     193    return establishIdentifierForPthreadHandle(threadHandle, data);
    178194}
    179195#else
     
    186202    }
    187203
    188     return establishIdentifierForPthreadHandle(threadHandle);
     204    return establishIdentifierForPthreadHandle(threadHandle, data);
    189205}
    190206#endif
     
    236252
    237253    // Not a WTF-created thread, ThreadIdentifier is not established yet.
    238     id = establishIdentifierForPthreadHandle(pthread_self());
     254    id = establishIdentifierForPthreadHandle(pthread_self(), 0);
    239255    ThreadIdentifierData::initialize(id);
    240256    return id;
     
    250266}
    251267
     268void* threadContext(ThreadIdentifier id)
     269{
     270    return contextForIdentifier(id);
     271}
     272
    252273Mutex::Mutex()
    253274{
  • trunk/JavaScriptCore/wtf/ThreadingWin.cpp

    r53714 r55234  
    119119#pragma pack(pop)
    120120
     121typedef struct {
     122    HANDLE handle;
     123    void* context;
     124} ThreadInfo;
     125
    121126void initializeCurrentThreadInternal(const char* szThreadName)
    122127{
     
    166171}
    167172
    168 static HashMap<DWORD, HANDLE>& threadMap()
    169 {
    170     static HashMap<DWORD, HANDLE> map;
     173static HashMap<DWORD, ThreadInfo>& threadMap()
     174{
     175    static HashMap<DWORD, ThreadInfo> map;
    171176    return map;
    172177}
    173178
    174 static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle)
     179static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle, void* context)
    175180{
    176181    MutexLocker locker(threadMapMutex());
    177182    ASSERT(!threadMap().contains(threadID));
    178     threadMap().add(threadID, threadHandle);
     183    ThreadInfo info;
     184    info.handle = threadHandle;
     185    info.context = context;
     186    threadMap().add(threadID, info);
    179187}
    180188
     
    182190{
    183191    MutexLocker locker(threadMapMutex());
    184     return threadMap().get(id);
     192    return threadMap().get(id).handle;
     193}
     194
     195static void* contextForIdentifier(ThreadIdentifier id)
     196{
     197    MutexLocker locker(threadMapMutex());
     198    return threadMap().get(id).context;
    185199}
    186200
     
    238252
    239253    threadID = static_cast<ThreadIdentifier>(threadIdentifier);
    240     storeThreadHandleByIdentifier(threadIdentifier, threadHandle);
     254    storeThreadHandleByIdentifier(threadIdentifier, threadHandle, data);
    241255
    242256    return threadID;
     
    279293{
    280294    return currentThread() == mainThreadIdentifier;
     295}
     296
     297void* threadContext(ThreadIdentifier threadID)
     298{
     299    return contextForIdentifier(threadID);
    281300}
    282301
Note: See TracChangeset for help on using the changeset viewer.