Title: [92154] trunk/Source/_javascript_Core
- Revision
- 92154
- Author
- le...@chromium.org
- Date
- 2011-08-01 17:10:21 -0700 (Mon, 01 Aug 2011)
Log 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.
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (92153 => 92154)
--- trunk/Source/_javascript_Core/ChangeLog 2011-08-02 00:07:14 UTC (rev 92153)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-08-02 00:10:21 UTC (rev 92154)
@@ -1,3 +1,24 @@
+2011-07-14 David Levin <le...@chromium.org>
+
+ 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.
+
2011-08-01 Filip Pizlo <fpi...@apple.com>
DFG JIT sometimes creates speculation check data structures that have
Modified: trunk/Source/_javascript_Core/wtf/ThreadIdentifierDataPthreads.cpp (92153 => 92154)
--- trunk/Source/_javascript_Core/wtf/ThreadIdentifierDataPthreads.cpp 2011-08-02 00:07:14 UTC (rev 92153)
+++ trunk/Source/_javascript_Core/wtf/ThreadIdentifierDataPthreads.cpp 2011-08-02 00:10:21 UTC (rev 92154)
@@ -36,10 +36,11 @@
#include "Threading.h"
+#include <limits.h>
+
namespace WTF {
-pthread_key_t ThreadIdentifierData::m_key;
-static pthread_once_t _onceControl_ = PTHREAD_ONCE_INIT;
+pthread_key_t ThreadIdentifierData::m_key = PTHREAD_KEYS_MAX;
void clearPthreadHandleForIdentifier(ThreadIdentifier);
@@ -48,9 +49,15 @@
clearPthreadHandleForIdentifier(m_identifier);
}
+void ThreadIdentifierData::initializeOnce()
+{
+ if (pthread_key_create(&m_key, destruct))
+ CRASH();
+}
+
ThreadIdentifier ThreadIdentifierData::identifier()
{
- initializeKeyOnce();
+ ASSERT(m_key != PTHREAD_KEYS_MAX);
ThreadIdentifierData* threadIdentifierData = static_cast<ThreadIdentifierData*>(pthread_getspecific(m_key));
return threadIdentifierData ? threadIdentifierData->m_identifier : 0;
@@ -59,8 +66,6 @@
void ThreadIdentifierData::initialize(ThreadIdentifier id)
{
ASSERT(!identifier());
-
- initializeKeyOnce();
pthread_setspecific(m_key, new ThreadIdentifierData(id));
}
@@ -79,18 +84,6 @@
pthread_setspecific(m_key, threadIdentifierData);
}
-void ThreadIdentifierData::initializeKeyOnceHelper()
-{
- if (pthread_key_create(&m_key, destruct))
- CRASH();
-}
-
-void ThreadIdentifierData::initializeKeyOnce()
-{
- if (pthread_once(&onceControl, initializeKeyOnceHelper))
- CRASH();
-}
-
} // namespace WTF
#endif // USE(PTHREADS)
Modified: trunk/Source/_javascript_Core/wtf/ThreadIdentifierDataPthreads.h (92153 => 92154)
--- trunk/Source/_javascript_Core/wtf/ThreadIdentifierDataPthreads.h 2011-08-02 00:07:14 UTC (rev 92153)
+++ trunk/Source/_javascript_Core/wtf/ThreadIdentifierDataPthreads.h 2011-08-02 00:10:21 UTC (rev 92154)
@@ -42,6 +42,10 @@
public:
~ThreadIdentifierData();
+ // One time initialization for this class as a whole.
+ // This method must be called before initialize() and it is not thread-safe.
+ static void initializeOnce();
+
// Creates and puts an instance of ThreadIdentifierData into thread-specific storage.
static void initialize(ThreadIdentifier identifier);
@@ -62,9 +66,6 @@
// ThreadIdentifier from the threadMap, completing the cleanup.
static void destruct(void* data);
- static void initializeKeyOnceHelper();
- static void initializeKeyOnce();
-
ThreadIdentifier m_identifier;
bool m_isDestroyedOnce;
static pthread_key_t m_key;
Modified: trunk/Source/_javascript_Core/wtf/ThreadingPthreads.cpp (92153 => 92154)
--- trunk/Source/_javascript_Core/wtf/ThreadingPthreads.cpp 2011-08-02 00:07:14 UTC (rev 92153)
+++ trunk/Source/_javascript_Core/wtf/ThreadingPthreads.cpp 2011-08-02 00:10:21 UTC (rev 92154)
@@ -86,6 +86,7 @@
atomicallyInitializedStaticMutex = new Mutex;
threadMapMutex();
initializeRandomNumberGenerator();
+ ThreadIdentifierData::initializeOnce();
wtfThreadData();
#if ENABLE(WTF_MULTIPLE_THREADS)
s_dtoaP5Mutex = new Mutex;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes