Changeset 74975 in webkit
- Timestamp:
- Jan 4, 2011 10:56:18 AM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r74973 r74975 1 2011-01-04 Daniel Bates <dbates@rim.com> 2 3 Reviewed by Adam Roben. 4 5 Extract ThreadFunctionInvocation into separate file and share between Apple Windows and Android 6 https://bugs.webkit.org/show_bug.cgi?id=51855 7 8 Both the Apple Windows and Android ports implement a similar adapter structure, 9 called ThreadFunctionInvocation and ThreadData respectively, as part of 10 their thread creation process. Instead, we should share such an adapter 11 structure and remove duplicate code. 12 13 * JavaScriptCore.gypi: Added header wtf/ThreadFunctionInvocation.h. 14 * wtf/ThreadFunctionInvocation.h: Added. 15 (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): 16 * wtf/ThreadingPthreads.cpp: Removed Android-specific structure ThreadData; Instead, use ThreadFunctionInvocation. 17 (WTF::runThreadWithRegistration): 18 (WTF::createThreadInternal): 19 * wtf/ThreadingWin.cpp: Moved structure ThreadFunctionInvocation to its own file so that 20 it can be shared with the Android implementation of createThreadInternal(). 21 (WTF::wtfThreadEntryPoint): Use OwnPtr to hold passed instance of ThreadFunctionInvocation. 22 1 23 2011-01-03 Daniel Bates <dbates@rim.com> 2 24 -
trunk/Source/JavaScriptCore/JavaScriptCore.gypi
r74600 r74975 441 441 'wtf/TCSystemAlloc.cpp', 442 442 'wtf/TCSystemAlloc.h', 443 'wtf/ThreadFunctionInvocation.h', 443 444 'wtf/ThreadIdentifierDataPthreads.cpp', 444 445 'wtf/ThreadIdentifierDataPthreads.h', -
trunk/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp
r68209 r74975 51 51 #if OS(ANDROID) 52 52 #include "JNIUtility.h" 53 #include "ThreadFunctionInvocation.h" 54 #include <wtf/OwnPtr.h> 53 55 #endif 54 56 … … 137 139 138 140 #if OS(ANDROID) 139 // On the Android platform, threads must be registered with the VM before they run.140 struct ThreadData {141 ThreadFunction entryPoint;142 void* arg;143 };144 145 141 static void* runThreadWithRegistration(void* arg) 146 142 { 147 ThreadData* data = static_cast<ThreadData*>(arg);143 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(static_cast<ThreadFunctionInvocation*>(arg)); 148 144 JavaVM* vm = JSC::Bindings::getJavaVM(); 149 145 JNIEnv* env; 150 146 void* ret = 0; 151 147 if (vm->AttachCurrentThread(&env, 0) == JNI_OK) { 152 ret = data->entryPoint(data->arg);148 ret = invocation->function(invocation.data); 153 149 vm->DetachCurrentThread(); 154 150 } 155 delete data;156 151 return ret; 157 152 } … … 160 155 { 161 156 pthread_t threadHandle; 162 ThreadData* threadData = new ThreadData(); 163 threadData->entryPoint = entryPoint;164 threadData->arg = data;165 166 if (pthread_create(&threadHandle, 0, runThreadWithRegistration, static_cast<void*>(threadData))) {157 158 // On the Android platform, threads must be registered with the VM before they run. 159 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInvocation(entryPoint, data)); 160 161 if (pthread_create(&threadHandle, 0, runThreadWithRegistration, invocation.get())) { 167 162 LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data); 168 delete threadData;169 163 return 0; 170 164 } 165 166 // The thread will take ownership of invocation. 167 invocation.leakPtr(); 168 171 169 return establishIdentifierForPthreadHandle(threadHandle); 172 170 } -
trunk/Source/JavaScriptCore/wtf/ThreadingWin.cpp
r64384 r74975 88 88 89 89 #include "MainThread.h" 90 #include "ThreadFunctionInvocation.h" 90 91 #if !USE(PTHREADS) && OS(WINDOWS) 91 92 #include "ThreadSpecific.h" … … 103 104 #include <wtf/HashMap.h> 104 105 #include <wtf/MathExtras.h> 106 #include <wtf/OwnPtr.h> 105 107 #include <wtf/RandomNumberSeed.h> 106 108 … … 188 190 } 189 191 190 struct ThreadFunctionInvocation {191 ThreadFunctionInvocation(ThreadFunction function, void* data) : function(function), data(data) {}192 193 ThreadFunction function;194 void* data;195 };196 197 192 static unsigned __stdcall wtfThreadEntryPoint(void* param) 198 193 { 199 ThreadFunctionInvocation invocation = *static_cast<ThreadFunctionInvocation*>(param); 200 delete static_cast<ThreadFunctionInvocation*>(param); 201 202 void* result = invocation.function(invocation.data); 194 OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(static_cast<ThreadFunctionInvocation*>(param)); 195 void* result = invocation->function(invocation.data); 203 196 204 197 #if !USE(PTHREADS) && OS(WINDOWS)
Note: See TracChangeset
for help on using the changeset viewer.