From ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 24 Feb 2012 16:36:50 +0100 Subject: Imported WebKit commit bb52bf3c0119e8a128cd93afe5572413a8617de9 (http://svn.webkit.org/repository/webkit/trunk@108790) --- Source/JavaScriptCore/wtf/ThreadingPthreads.cpp | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'Source/JavaScriptCore/wtf/ThreadingPthreads.cpp') diff --git a/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp b/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp index 763ec2bbb..abd350dbb 100644 --- a/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp +++ b/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp @@ -40,9 +40,12 @@ #include "HashMap.h" #include "RandomNumberSeed.h" #include "StdLibExtras.h" +#include "ThreadFunctionInvocation.h" #include "ThreadIdentifierDataPthreads.h" #include "ThreadSpecific.h" #include "UnusedParam.h" +#include +#include #include #include @@ -152,6 +155,15 @@ void clearPthreadHandleForIdentifier(ThreadIdentifier id) threadMap().remove(id); } +static void* wtfThreadEntryPoint(void* param) +{ + // Balanced by .leakPtr() in createThreadInternal. + OwnPtr invocation = adoptPtr(static_cast(param)); + invocation->function(invocation->data); + + return 0; +} + #if PLATFORM(BLACKBERRY) ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char* threadName) { @@ -171,8 +183,9 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con LOG_ERROR("pthread_attr_getstack() failed: %d", errno); } + OwnPtr invocation = adoptPtr(new ThreadFunctionInvocation(entryPoint, data)); pthread_t threadHandle; - if (pthread_create(&threadHandle, &attr, entryPoint, data)) { + if (pthread_create(&threadHandle, &attr, wtfThreadEntryPoint, invocation.get())) { LOG_ERROR("pthread_create() failed: %d", errno); threadHandle = 0; } @@ -183,17 +196,26 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con if (!threadHandle) return 0; + // Balanced by adoptPtr() in wtfThreadEntryPoint. + ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr(); + UNUSED_PARAM(leakedInvocation); + return establishIdentifierForPthreadHandle(threadHandle); } #else ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*) { + OwnPtr invocation = adoptPtr(new ThreadFunctionInvocation(entryPoint, data)); pthread_t threadHandle; - if (pthread_create(&threadHandle, 0, entryPoint, data)) { - LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data); + if (pthread_create(&threadHandle, 0, wtfThreadEntryPoint, invocation.get())) { + LOG_ERROR("Failed to create pthread at entry point %p with data %p", wtfThreadEntryPoint, invocation.get()); return 0; } + // Balanced by adoptPtr() in wtfThreadEntryPoint. + ThreadFunctionInvocation* leakedInvocation = invocation.leakPtr(); + UNUSED_PARAM(leakedInvocation); + return establishIdentifierForPthreadHandle(threadHandle); } #endif @@ -217,7 +239,7 @@ void initializeCurrentThreadInternal(const char* threadName) ThreadIdentifierData::initialize(id); } -int waitForThreadCompletion(ThreadIdentifier threadID, void** result) +int waitForThreadCompletion(ThreadIdentifier threadID) { ASSERT(threadID); @@ -225,7 +247,7 @@ int waitForThreadCompletion(ThreadIdentifier threadID, void** result) if (!pthreadHandle) return 0; - int joinResult = pthread_join(pthreadHandle, result); + int joinResult = pthread_join(pthreadHandle, 0); if (joinResult == EDEADLK) LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID); -- cgit v1.2.1