Ignore:
Timestamp:
Aug 1, 2011, 5:10:21 PM (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

    r91444 r92154  
    3737#include "Threading.h"
    3838
     39#include <limits.h>
     40
    3941namespace WTF {
    4042
    41 pthread_key_t ThreadIdentifierData::m_key;
    42 static pthread_once_t onceControl = PTHREAD_ONCE_INIT;
     43pthread_key_t ThreadIdentifierData::m_key = PTHREAD_KEYS_MAX;
    4344
    4445void clearPthreadHandleForIdentifier(ThreadIdentifier);
     
    4950}
    5051
     52void ThreadIdentifierData::initializeOnce()
     53{
     54    if (pthread_key_create(&m_key, destruct))
     55        CRASH();
     56}
     57
    5158ThreadIdentifier ThreadIdentifierData::identifier()
    5259{
    53     initializeKeyOnce();
     60    ASSERT(m_key != PTHREAD_KEYS_MAX);
    5461    ThreadIdentifierData* threadIdentifierData = static_cast<ThreadIdentifierData*>(pthread_getspecific(m_key));
    5562
     
    6067{
    6168    ASSERT(!identifier());
    62 
    63     initializeKeyOnce();
    6469    pthread_setspecific(m_key, new ThreadIdentifierData(id));
    6570}
     
    8085}
    8186
    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 
    9487} // namespace WTF
    9588
Note: See TracChangeset for help on using the changeset viewer.