Ignore:
Timestamp:
Jul 15, 2011, 11:49:24 AM (14 years ago)
Author:
[email protected]
Message:

currentThread is too slow!
https://bugs.webkit.org/show_bug.cgi?id=64577

Reviewed by Darin Adler and Dmitry Titov.

The problem is that currentThread results in a pthread_once call which always takes a lock.
With this change, currentThread is 10% faster than isMainThread in release mode and only
5% slower than isMainThread in debug.

  • wtf/ThreadIdentifierDataPthreads.cpp:

(WTF::ThreadIdentifierData::initializeOnce): Remove the pthread once stuff
which is no longer needed because this is called from initializeThreading().
(WTF::ThreadIdentifierData::identifier): Remove the initializeKeyOnce call because
intialization of the pthread key should already be done.
(WTF::ThreadIdentifierData::initialize): Ditto.

  • wtf/ThreadIdentifierDataPthreads.h:
  • wtf/ThreadingPthreads.cpp:

(WTF::initializeThreading): Acquire the pthread key here.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/ThreadIdentifierDataPthreads.cpp

    r90939 r91082  
    3939namespace WTF {
    4040
    41 pthread_key_t ThreadIdentifierData::m_key;
    42 static pthread_once_t onceControl = PTHREAD_ONCE_INIT;
     41pthread_key_t ThreadIdentifierData::m_key = PTHREAD_KEYS_MAX;
    4342
    4443void clearPthreadHandleForIdentifier(ThreadIdentifier);
     
    4948}
    5049
     50void ThreadIdentifierData::initializeOnce()
     51{
     52    if (pthread_key_create(&m_key, destruct))
     53        CRASH();
     54}
     55
    5156ThreadIdentifier ThreadIdentifierData::identifier()
    5257{
    53     initializeKeyOnce();
     58    ASSERT(m_key != PTHREAD_KEYS_MAX);
    5459    ThreadIdentifierData* threadIdentifierData = static_cast<ThreadIdentifierData*>(pthread_getspecific(m_key));
    5560
     
    6065{
    6166    ASSERT(!identifier());
    62 
    63     initializeKeyOnce();
    6467    pthread_setspecific(m_key, new ThreadIdentifierData(id));
    6568}
     
    8083}
    8184
    82 void ThreadIdentifierData::initializeKeyOnceHelper()
    83 {
    84     if (pthread_key_create(&m_key, destruct))
    85         CRASH();
    86 }
    87 
    88 void ThreadIdentifierData::initializeKeyOnce()
    89 {
    90     if (pthread_once(&onceControl, initializeKeyOnceHelper))
    91         CRASH();
    92 }
    93 
    9485} // namespace WTF
    9586
Note: See TracChangeset for help on using the changeset viewer.