[SCM] WebKit Debian packaging branch, debian/experimental, updated. debian/1.3.8-1-1049-g2e11a8e

dbates at webkit.org dbates at webkit.org
Fri Jan 21 14:54:47 UTC 2011


The following commit has been merged in the debian/experimental branch:
commit 52a42d512d6f06e35ab5971d5707514f344cc3c9
Author: dbates at webkit.org <dbates at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 4 18:56:18 2011 +0000

    2011-01-04  Daniel Bates  <dbates at 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.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74975 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index e5d8a55..54a00f1 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,25 @@
+2011-01-04  Daniel Bates  <dbates at 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.
+
 2011-01-03  Daniel Bates  <dbates at rim.com>
 
         Reviewed by Darin Adler.
diff --git a/Source/JavaScriptCore/JavaScriptCore.gypi b/Source/JavaScriptCore/JavaScriptCore.gypi
index aadfeac..e60969e 100644
--- a/Source/JavaScriptCore/JavaScriptCore.gypi
+++ b/Source/JavaScriptCore/JavaScriptCore.gypi
@@ -440,6 +440,7 @@
             'wtf/TCSpinLock.h',
             'wtf/TCSystemAlloc.cpp',
             'wtf/TCSystemAlloc.h',
+            'wtf/ThreadFunctionInvocation.h',
             'wtf/ThreadIdentifierDataPthreads.cpp',
             'wtf/ThreadIdentifierDataPthreads.h',
             'wtf/Threading.cpp',
diff --git a/Source/JavaScriptCore/wtf/ThreadFunctionInvocation.h b/Source/JavaScriptCore/wtf/ThreadFunctionInvocation.h
new file mode 100644
index 0000000..f1e1472
--- /dev/null
+++ b/Source/JavaScriptCore/wtf/ThreadFunctionInvocation.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ThreadFunctionInvocation_h
+#define ThreadFunctionInvocation_h
+
+namespace WTF {
+
+typedef void* (*ThreadFunction)(void* argument);
+
+struct ThreadFunctionInvocation {
+    ThreadFunctionInvocation(ThreadFunction function, void* data)
+        : function(function)
+        , data(data)
+    {
+    }
+
+    ThreadFunction function;
+    void* data;
+};
+
+} // namespace WTF
+
+#endif // ThreadFunctionInvocation_h
diff --git a/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp b/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp
index 0017a6f..8ff1d78 100644
--- a/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp
+++ b/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp
@@ -50,6 +50,8 @@
 
 #if OS(ANDROID)
 #include "JNIUtility.h"
+#include "ThreadFunctionInvocation.h"
+#include <wtf/OwnPtr.h>
 #endif
 
 namespace WTF {
@@ -136,38 +138,34 @@ void clearPthreadHandleForIdentifier(ThreadIdentifier id)
 }
 
 #if OS(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);
+    OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(static_cast<ThreadFunctionInvocation*>(arg));
     JavaVM* vm = JSC::Bindings::getJavaVM();
     JNIEnv* env;
     void* ret = 0;
     if (vm->AttachCurrentThread(&env, 0) == JNI_OK) {
-        ret = data->entryPoint(data->arg);
+        ret = invocation->function(invocation.data);
         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))) {
+    // On the Android platform, threads must be registered with the VM before they run.
+    OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(new ThreadFunctionInvocation(entryPoint, data));
+
+    if (pthread_create(&threadHandle, 0, runThreadWithRegistration, invocation.get())) {
         LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data);
-        delete threadData;
         return 0;
     }
+
+    // The thread will take ownership of invocation.
+    invocation.leakPtr();
+
     return establishIdentifierForPthreadHandle(threadHandle);
 }
 #else
diff --git a/Source/JavaScriptCore/wtf/ThreadingWin.cpp b/Source/JavaScriptCore/wtf/ThreadingWin.cpp
index a29fbbb..d5cf528 100644
--- a/Source/JavaScriptCore/wtf/ThreadingWin.cpp
+++ b/Source/JavaScriptCore/wtf/ThreadingWin.cpp
@@ -87,6 +87,7 @@
 #include "Threading.h"
 
 #include "MainThread.h"
+#include "ThreadFunctionInvocation.h"
 #if !USE(PTHREADS) && OS(WINDOWS)
 #include "ThreadSpecific.h"
 #endif
@@ -102,6 +103,7 @@
 #include <wtf/CurrentTime.h>
 #include <wtf/HashMap.h>
 #include <wtf/MathExtras.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/RandomNumberSeed.h>
 
 namespace WTF {
@@ -187,19 +189,10 @@ static void clearThreadHandleForIdentifier(ThreadIdentifier id)
     threadMap().remove(id);
 }
 
-struct ThreadFunctionInvocation {
-    ThreadFunctionInvocation(ThreadFunction function, void* data) : function(function), data(data) {}
-
-    ThreadFunction function;
-    void* data;
-};
-
 static unsigned __stdcall wtfThreadEntryPoint(void* param)
 {
-    ThreadFunctionInvocation invocation = *static_cast<ThreadFunctionInvocation*>(param);
-    delete static_cast<ThreadFunctionInvocation*>(param);
-
-    void* result = invocation.function(invocation.data);
+    OwnPtr<ThreadFunctionInvocation> invocation = adoptPtr(static_cast<ThreadFunctionInvocation*>(param));
+    void* result = invocation->function(invocation.data);
 
 #if !USE(PTHREADS) && OS(WINDOWS)
     // Do the TLS cleanup.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list