diff options
Diffstat (limited to 'src/3rdparty/webkit/JavaScriptCore/wtf/ThreadingPthreads.cpp')
-rw-r--r-- | src/3rdparty/webkit/JavaScriptCore/wtf/ThreadingPthreads.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/wtf/ThreadingPthreads.cpp b/src/3rdparty/webkit/JavaScriptCore/wtf/ThreadingPthreads.cpp index 6cad5e3..2feb808 100644 --- a/src/3rdparty/webkit/JavaScriptCore/wtf/ThreadingPthreads.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/wtf/ThreadingPthreads.cpp @@ -37,6 +37,8 @@ #include "MainThread.h" #include "RandomNumberSeed.h" #include "StdLibExtras.h" +#include "ThreadIdentifierDataPthreads.h" +#include "ThreadSpecific.h" #include "UnusedParam.h" #include <errno.h> @@ -45,7 +47,7 @@ #include <sys/time.h> #endif -#if PLATFORM(ANDROID) +#if OS(ANDROID) #include "jni_utility.h" #endif @@ -55,10 +57,12 @@ typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap; static Mutex* atomicallyInitializedStaticMutex; -#if !PLATFORM(DARWIN) || PLATFORM(CHROMIUM) -static ThreadIdentifier mainThreadIdentifier; // The thread that was the first to call initializeThreading(), which must be the main thread. +#if !OS(DARWIN) || PLATFORM(CHROMIUM) || USE(WEB_THREAD) +static pthread_t mainThread; // The thread that was the first to call initializeThreading(), which must be the main thread. #endif +void clearPthreadHandleForIdentifier(ThreadIdentifier); + static Mutex& threadMapMutex() { DEFINE_STATIC_LOCAL(Mutex, mutex, ()); @@ -71,8 +75,8 @@ void initializeThreading() atomicallyInitializedStaticMutex = new Mutex; threadMapMutex(); initializeRandomNumberGenerator(); -#if !PLATFORM(DARWIN) || PLATFORM(CHROMIUM) - mainThreadIdentifier = currentThread(); +#if !OS(DARWIN) || PLATFORM(CHROMIUM) || USE(WEB_THREAD) + mainThread = pthread_self(); #endif initializeMainThread(); } @@ -108,7 +112,7 @@ static ThreadIdentifier identifierByPthreadHandle(const pthread_t& pthreadHandle return 0; } -static ThreadIdentifier establishIdentifierForPthreadHandle(pthread_t& pthreadHandle) +static ThreadIdentifier establishIdentifierForPthreadHandle(const pthread_t& pthreadHandle) { ASSERT(!identifierByPthreadHandle(pthreadHandle)); @@ -128,7 +132,7 @@ static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id) return threadMap().get(id); } -static void clearPthreadHandleForIdentifier(ThreadIdentifier id) +void clearPthreadHandleForIdentifier(ThreadIdentifier id) { MutexLocker locker(threadMapMutex()); @@ -137,7 +141,7 @@ static void clearPthreadHandleForIdentifier(ThreadIdentifier id) threadMap().remove(id); } -#if PLATFORM(ANDROID) +#if OS(ANDROID) // On the Android platform, threads must be registered with the VM before they run. struct ThreadData { ThreadFunction entryPoint; @@ -185,13 +189,17 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con } #endif -void setThreadNameInternal(const char* threadName) +void initializeCurrentThreadInternal(const char* threadName) { #if HAVE(PTHREAD_SETNAME_NP) pthread_setname_np(threadName); #else UNUSED_PARAM(threadName); #endif + + ThreadIdentifier id = identifierByPthreadHandle(pthread_self()); + ASSERT(id); + ThreadIdentifierData::initialize(id); } int waitForThreadCompletion(ThreadIdentifier threadID, void** result) @@ -199,12 +207,13 @@ int waitForThreadCompletion(ThreadIdentifier threadID, void** result) ASSERT(threadID); pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID); + if (!pthreadHandle) + return 0; int joinResult = pthread_join(pthreadHandle, result); if (joinResult == EDEADLK) LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID); - clearPthreadHandleForIdentifier(threadID); return joinResult; } @@ -213,26 +222,30 @@ void detachThread(ThreadIdentifier threadID) ASSERT(threadID); pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID); + if (!pthreadHandle) + return; pthread_detach(pthreadHandle); - - clearPthreadHandleForIdentifier(threadID); } ThreadIdentifier currentThread() { - pthread_t currentThread = pthread_self(); - if (ThreadIdentifier id = identifierByPthreadHandle(currentThread)) + ThreadIdentifier id = ThreadIdentifierData::identifier(); + if (id) return id; - return establishIdentifierForPthreadHandle(currentThread); + + // Not a WTF-created thread, ThreadIdentifier is not established yet. + id = establishIdentifierForPthreadHandle(pthread_self()); + ThreadIdentifierData::initialize(id); + return id; } bool isMainThread() { -#if PLATFORM(DARWIN) && !PLATFORM(CHROMIUM) +#if OS(DARWIN) && !PLATFORM(CHROMIUM) && !USE(WEB_THREAD) return pthread_main_np(); #else - return currentThread() == mainThreadIdentifier; + return pthread_equal(pthread_self(), mainThread); #endif } |