Commit 3de6eb1a authored by levin@chromium.org's avatar levin@chromium.org
Browse files

2009-04-09 Ben Murdoch <benm@google.com>

        Reviewed by Alexey Proskuryakov.

        The Android platform requires threads to be registered with the VM.
        This patch implements this behaviour inside ThreadingPthreads.cpp.

        * wtf/ThreadingPthreads.cpp: Add a level above threadEntryPoint that takes care of (un)registering threads with the VM.
        (WTF::runThreadWithRegistration): register the thread and run entryPoint. Unregister the thread afterwards.
        (WTF::createThreadInternal): call runThreadWithRegistration instead of entryPoint directly.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@42366 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f239bbf9
2009-04-09 Ben Murdoch <benm@google.com>
Reviewed by Alexey Proskuryakov.
https://bugs.webkit.org/show_bug.cgi?id=25091
The Android platform requires threads to be registered with the VM.
This patch implements this behaviour inside ThreadingPthreads.cpp.
* wtf/ThreadingPthreads.cpp: Add a level above threadEntryPoint that takes care of (un)registering threads with the VM.
(WTF::runThreadWithRegistration): register the thread and run entryPoint. Unregister the thread afterwards.
(WTF::createThreadInternal): call runThreadWithRegistration instead of entryPoint directly.
2009-04-09 David Kilzer <ddkilzer@apple.com>
 
Reinstating <rdar://problem/6718589> Option to turn off SVG DOM Objective-C bindings
......@@ -42,6 +42,10 @@
#include <limits.h>
#include <sys/time.h>
#if PLATFORM(ANDROID)
#include "jni_utility.h"
#endif
namespace WTF {
typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap;
......@@ -130,6 +134,41 @@ static void clearPthreadHandleForIdentifier(ThreadIdentifier id)
threadMap().remove(id);
}
#if PLATFORM(ANDROID)
// On the Android platform, threads must be registered with the VM before they run.
struct ThreadData {
ThreadFunction entryPoint;
void* arg;
};
static void* runThreadWithRegistration(void* arg)
{
ThreadData* data = static_cast<ThreadData*>(arg);
JavaVM* vm = JSC::Bindings::getJavaVM();
JNIEnv* env;
void* ret = 0;
if (vm->AttachCurrentThread(&env, 0) == JNI_OK) {
ret = data->entryPoint(data->arg);
vm->DetachCurrentThread();
}
delete data;
return ret;
}
ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*)
{
pthread_t threadHandle;
ThreadData* threadData = new ThreadData();
threadData->entryPoint = entryPoint;
threadData->arg = data;
if (pthread_create(&threadHandle, 0, runThreadWithRegistration, static_cast<void*>(threadData))) {
LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
return 0;
}
return establishIdentifierForPthreadHandle(threadHandle);
}
#else
ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*)
{
pthread_t threadHandle;
......@@ -140,6 +179,7 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
return establishIdentifierForPthreadHandle(threadHandle);
}
#endif
void setThreadNameInternal(const char* threadName)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment