diff options
author | Patrick Scott <phanna@android.com> | 2009-07-28 14:44:16 -0400 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2009-07-28 15:22:50 -0400 |
commit | 173247db5500c88f7a7229fd20fb49ebd2d49296 (patch) | |
tree | 60b61c7db8da953773114faeab3723ba0f65313a | |
parent | 70522f5f5fb44f2f4df7a08aa64263c619e299cb (diff) | |
download | webkit-donut.tar.gz |
Do not merge.android-sdk-tools_r2android-sdk-1.6_r2android-sdk-1.6_r1android-sdk-1.6-docs_r1android-1.6_r2android-1.6_r1.5android-1.6_r1.4android-1.6_r1.3android-1.6_r1.2android-1.6_r1.1android-1.6_r1donut-release2donut-releasedonut
This will attach and detach the native thread to and from the java vm. I believe
this was the cause of a crash in donut. Sometimes, the IconDatabase needs to
notify the WebCore thread of a new Icon. These callbacks post messages through
the vm which causes AttachCurrentThread to be called but no matching
DetachCurrentThread when the thread exits.
Bug:1977972
-rw-r--r-- | JavaScriptCore/wtf/ThreadingPthreads.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/JavaScriptCore/wtf/ThreadingPthreads.cpp b/JavaScriptCore/wtf/ThreadingPthreads.cpp index 105e42af6..8a2c943e3 100644 --- a/JavaScriptCore/wtf/ThreadingPthreads.cpp +++ b/JavaScriptCore/wtf/ThreadingPthreads.cpp @@ -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,42 @@ 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); + delete threadData; + return 0; + } + return establishIdentifierForPthreadHandle(threadHandle); +} +#else ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, const char*) { pthread_t threadHandle; @@ -140,6 +180,7 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con return establishIdentifierForPthreadHandle(threadHandle); } +#endif int waitForThreadCompletion(ThreadIdentifier threadID, void** result) { |