Ignore:
Timestamp:
Feb 25, 2010, 10:27:45 AM (15 years ago)
Author:
[email protected]
Message:

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

Patch by Jochen Eisinger <[email protected]> on 2010-02-25
Reviewed by Jeremy Orlow.

When a database is opened, right now you
don't have any context from where it is opened. The problem is that
the actual calls that open a database go through the sqlite3 vfs
layer, so there's no easy way to pass this function down to to
platform/sql/chromium/SQLFileSystemChromium*.cpp

This patch will allow you to get from anywhere within webkit a pointer
to the Thread object that actually created the thread you're currently
on (in case of the database, this can be either a thread forked of
from the main thread or from a worker thread), and query the object
for context information.

  • 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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

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