Changeset 74975 in webkit


Ignore:
Timestamp:
Jan 4, 2011 10:56:18 AM (13 years ago)
Author:
dbates@webkit.org
Message:

2011-01-04 Daniel Bates <dbates@rim.com>

Reviewed by Adam Roben.

Extract ThreadFunctionInvocation into separate file and share between Apple Windows and Android
https://bugs.webkit.org/show_bug.cgi?id=51855

Both the Apple Windows and Android ports implement a similar adapter structure,
called ThreadFunctionInvocation and ThreadData respectively, as part of
their thread creation process. Instead, we should share such an adapter
structure and remove duplicate code.

  • JavaScriptCore.gypi: Added header wtf/ThreadFunctionInvocation.h.
  • wtf/ThreadFunctionInvocation.h: Added. (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation):
  • wtf/ThreadingPthreads.cpp: Removed Android-specific structure ThreadData; Instead, use ThreadFunctionInvocation. (WTF::runThreadWithRegistration): (WTF::createThreadInternal):
  • wtf/ThreadingWin.cpp: Moved structure ThreadFunctionInvocation to its own file so that it can be shared with the Android implementation of createThreadInternal(). (WTF::wtfThreadEntryPoint): Use OwnPtr to hold passed instance of ThreadFunctionInvocation.
Location:
trunk/Source/JavaScriptCore
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r74973 r74975  
     12011-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
    1232011-01-03  Daniel Bates  <dbates@rim.com>
    224
  • trunk/Source/JavaScriptCore/JavaScriptCore.gypi

    r74600 r74975  
    441441            'wtf/TCSystemAlloc.cpp',
    442442            'wtf/TCSystemAlloc.h',
     443            'wtf/ThreadFunctionInvocation.h',
    443444            'wtf/ThreadIdentifierDataPthreads.cpp',
    444445            'wtf/ThreadIdentifierDataPthreads.h',
  • trunk/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r68209 r74975  
    5151#if OS(ANDROID)
    5252#include "JNIUtility.h"
     53#include "ThreadFunctionInvocation.h"
     54#include <wtf/OwnPtr.h>
    5355#endif
    5456
     
    137139
    138140#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 
    145141static void* runThreadWithRegistration(void* arg)
    146142{
    147     ThreadData* data = static_cast<ThreadData*>(arg);
     143    OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(static_cast<ThreadFunctionInvocation*>(arg));
    148144    JavaVM* vm = JSC::Bindings::getJavaVM();
    149145    JNIEnv* env;
    150146    void* ret = 0;
    151147    if (vm->AttachCurrentThread(&env, 0) == JNI_OK) {
    152         ret = data->entryPoint(data->arg);
     148        ret = invocation->function(invocation.data);
    153149        vm->DetachCurrentThread();
    154150    }
    155     delete data;
    156151    return ret;
    157152}
     
    160155{
    161156    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())) {
    167162        LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
    168         delete threadData;
    169163        return 0;
    170164    }
     165
     166    // The thread will take ownership of invocation.
     167    invocation.leakPtr();
     168
    171169    return establishIdentifierForPthreadHandle(threadHandle);
    172170}
  • trunk/Source/JavaScriptCore/wtf/ThreadingWin.cpp

    r64384 r74975  
    8888
    8989#include "MainThread.h"
     90#include "ThreadFunctionInvocation.h"
    9091#if !USE(PTHREADS) && OS(WINDOWS)
    9192#include "ThreadSpecific.h"
     
    103104#include <wtf/HashMap.h>
    104105#include <wtf/MathExtras.h>
     106#include <wtf/OwnPtr.h>
    105107#include <wtf/RandomNumberSeed.h>
    106108
     
    188190}
    189191
    190 struct ThreadFunctionInvocation {
    191     ThreadFunctionInvocation(ThreadFunction function, void* data) : function(function), data(data) {}
    192 
    193     ThreadFunction function;
    194     void* data;
    195 };
    196 
    197192static unsigned __stdcall wtfThreadEntryPoint(void* param)
    198193{
    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);
    203196
    204197#if !USE(PTHREADS) && OS(WINDOWS)
Note: See TracChangeset for help on using the changeset viewer.