[WTF] Drop Thread::create(obsolete things) API since we can use lambda
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Jun 2017 18:19:36 +0000 (18:19 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Jun 2017 18:19:36 +0000 (18:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173825

Reviewed by Saam Barati.

Source/JavaScriptCore:

* jsc.cpp:
(startTimeoutThreadIfNeeded):
(timeoutThreadMain): Deleted.

Source/WebCore:

No behavior change.

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::IDBServer):
(WebCore::IDBServer::IDBServer::databaseThreadEntry): Deleted.
* Modules/indexeddb/server/IDBServer.h:
* Modules/webaudio/AsyncAudioDecoder.cpp:
(WebCore::AsyncAudioDecoder::AsyncAudioDecoder):
(WebCore::AsyncAudioDecoder::threadEntry): Deleted.
* Modules/webaudio/AsyncAudioDecoder.h:
* Modules/webaudio/OfflineAudioDestinationNode.cpp:
(WebCore::OfflineAudioDestinationNode::startRendering):
(WebCore::OfflineAudioDestinationNode::offlineRenderEntry): Deleted.
* Modules/webaudio/OfflineAudioDestinationNode.h:
* Modules/webdatabase/DatabaseThread.cpp:
(WebCore::DatabaseThread::start):
(WebCore::DatabaseThread::databaseThreadStart): Deleted.
* Modules/webdatabase/DatabaseThread.h:
* bindings/js/GCController.cpp:
(WebCore::collect):
(WebCore::GCController::gcTimerFired):
(WebCore::GCController::garbageCollectOnAlternateThreadForDebugging):
* loader/icon/IconDatabase.cpp:
(WebCore::IconDatabase::open):
(WebCore::IconDatabase::iconDatabaseSyncThreadStart): Deleted.
* loader/icon/IconDatabase.h:
* page/ResourceUsageThread.cpp:
(WebCore::ResourceUsageThread::createThreadIfNeeded):
(WebCore::ResourceUsageThread::threadCallback): Deleted.
* page/ResourceUsageThread.h:
* page/scrolling/ScrollingThread.cpp:
(WebCore::ScrollingThread::createThreadIfNeeded):
(WebCore::ScrollingThread::threadCallback): Deleted.
(WebCore::ScrollingThread::threadBody): Deleted.
* page/scrolling/ScrollingThread.h:
* platform/audio/HRTFDatabaseLoader.cpp:
(WebCore::HRTFDatabaseLoader::loadAsynchronously):
(WebCore::databaseLoaderEntry): Deleted.
* platform/audio/HRTFDatabaseLoader.h:
* platform/audio/ReverbConvolver.cpp:
(WebCore::ReverbConvolver::ReverbConvolver):
(WebCore::backgroundThreadEntry): Deleted.
* platform/audio/ReverbConvolver.h:
(WebCore::ReverbConvolver::useBackgroundThreads):
* platform/network/cf/LoaderRunLoopCF.cpp:
(WebCore::loaderRunLoop):
(WebCore::runLoaderThread): Deleted.
* platform/network/curl/CurlManager.cpp:
(WebCore::CurlManager::startThreadIfNeeded):
(WebCore::CurlManager::workerThread):
* platform/network/curl/CurlManager.h:
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::start):
(WebCore::WorkerThread::workerThreadStart): Deleted.
* workers/WorkerThread.h:

Source/WebKit:

* Storage/StorageThread.cpp:
(WebCore::StorageThread::start):
(WebCore::StorageThread::threadEntryPointCallback): Deleted.
* Storage/StorageThread.h:

Source/WTF:

Thread::create(ThreadFunction, void* data, const char* name) is a bit old API.
Since we have C++ lambda, the above API is simply unnecessary. And C++ lambda
based one is better since the above API needs casting data to and from void*.

* wtf/Function.h:
Avoid ambiguity.
* wtf/ParallelJobsGeneric.cpp:
(WTF::ParallelEnvironment::ThreadPrivate::tryLockFor):
(WTF::ParallelEnvironment::ThreadPrivate::workerThread): Deleted.
* wtf/ParallelJobsGeneric.h:
* wtf/Threading.cpp:
* wtf/ThreadingWin.cpp:
(WTF::createThread):

Tools:

* DumpRenderTree/JavaScriptThreading.cpp:
(runJavaScriptThread):
(startJavaScriptThreads):
* DumpRenderTree/mac/DumpRenderTree.mm:
(runThread):
(runPthread):
(testThreadIdentifierMap):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@218816 268f45cc-cd09-0410-ab3c-d52691b4dbfc

39 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/jsc.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/Function.h
Source/WTF/wtf/ParallelJobsGeneric.cpp
Source/WTF/wtf/ParallelJobsGeneric.h
Source/WTF/wtf/Threading.cpp
Source/WTF/wtf/ThreadingWin.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebCore/Modules/indexeddb/server/IDBServer.h
Source/WebCore/Modules/webaudio/AsyncAudioDecoder.cpp
Source/WebCore/Modules/webaudio/AsyncAudioDecoder.h
Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp
Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.h
Source/WebCore/Modules/webdatabase/DatabaseThread.cpp
Source/WebCore/Modules/webdatabase/DatabaseThread.h
Source/WebCore/bindings/js/GCController.cpp
Source/WebCore/loader/icon/IconDatabase.cpp
Source/WebCore/loader/icon/IconDatabase.h
Source/WebCore/page/ResourceUsageThread.cpp
Source/WebCore/page/ResourceUsageThread.h
Source/WebCore/page/scrolling/ScrollingThread.cpp
Source/WebCore/page/scrolling/ScrollingThread.h
Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp
Source/WebCore/platform/audio/HRTFDatabaseLoader.h
Source/WebCore/platform/audio/ReverbConvolver.cpp
Source/WebCore/platform/audio/ReverbConvolver.h
Source/WebCore/platform/network/cf/LoaderRunLoopCF.cpp
Source/WebCore/platform/network/curl/CurlManager.cpp
Source/WebCore/platform/network/curl/CurlManager.h
Source/WebCore/workers/WorkerThread.cpp
Source/WebCore/workers/WorkerThread.h
Source/WebKit/ChangeLog
Source/WebKit/Storage/StorageThread.cpp
Source/WebKit/Storage/StorageThread.h
Tools/ChangeLog
Tools/DumpRenderTree/JavaScriptThreading.cpp
Tools/DumpRenderTree/mac/DumpRenderTree.mm

index f9bff04..8ce31df 100644 (file)
@@ -1,3 +1,14 @@
+2017-06-26  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Drop Thread::create(obsolete things) API since we can use lambda
+        https://bugs.webkit.org/show_bug.cgi?id=173825
+
+        Reviewed by Saam Barati.
+
+        * jsc.cpp:
+        (startTimeoutThreadIfNeeded):
+        (timeoutThreadMain): Deleted.
+
 2017-06-26  Konstantin Tokarev  <annulen@yandex.ru>
 
         Unreviewed, add missing header for CLoop
index 6f176a9..a71fe76 100644 (file)
@@ -3173,22 +3173,20 @@ int jscmain(int argc, char** argv);
 static double s_desiredTimeout;
 static double s_timeoutMultiplier = 1.0;
 
-static NO_RETURN_DUE_TO_CRASH void timeoutThreadMain(void*)
-{
-    Seconds timeoutDuration(s_desiredTimeout * s_timeoutMultiplier);
-    sleep(timeoutDuration);
-    dataLog("Timed out after ", timeoutDuration, " seconds!\n");
-    CRASH();
-}
-
 static void startTimeoutThreadIfNeeded()
 {
     if (char* timeoutString = getenv("JSCTEST_timeout")) {
         if (sscanf(timeoutString, "%lf", &s_desiredTimeout) != 1) {
             dataLog("WARNING: timeout string is malformed, got ", timeoutString,
                 " but expected a number. Not using a timeout.\n");
-        } else
-            Thread::create(timeoutThreadMain, 0, "jsc Timeout Thread");
+        } else {
+            Thread::create("jsc Timeout Thread", [] () {
+                Seconds timeoutDuration(s_desiredTimeout * s_timeoutMultiplier);
+                sleep(timeoutDuration);
+                dataLog("Timed out after ", timeoutDuration, " seconds!\n");
+                CRASH();
+            });
+        }
     }
 }
 
index 7d7efbb..dca009c 100644 (file)
@@ -1,3 +1,24 @@
+2017-06-26  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Drop Thread::create(obsolete things) API since we can use lambda
+        https://bugs.webkit.org/show_bug.cgi?id=173825
+
+        Reviewed by Saam Barati.
+
+        Thread::create(ThreadFunction, void* data, const char* name) is a bit old API.
+        Since we have C++ lambda, the above API is simply unnecessary. And C++ lambda
+        based one is better since the above API needs casting data to and from void*.
+
+        * wtf/Function.h:
+        Avoid ambiguity.
+        * wtf/ParallelJobsGeneric.cpp:
+        (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor):
+        (WTF::ParallelEnvironment::ThreadPrivate::workerThread): Deleted.
+        * wtf/ParallelJobsGeneric.h:
+        * wtf/Threading.cpp:
+        * wtf/ThreadingWin.cpp:
+        (WTF::createThread):
+
 2017-06-25  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         initializeThreading() [first] causes WTFCrash due to maxSingleAllocationSize not being initialized
index 603048d..bd5b05c 100644 (file)
@@ -38,7 +38,7 @@ public:
     Function() = default;
     Function(std::nullptr_t) { }
 
-    template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type>
+    template<typename CallableType, class = typename std::enable_if<!(std::is_pointer<CallableType>::value && std::is_function<typename std::remove_pointer<CallableType>::type>::value) && std::is_rvalue_reference<CallableType&&>::value>::type>
     Function(CallableType&& callable)
         : m_callableWrapper(std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable)))
     {
@@ -59,7 +59,7 @@ public:
 
     explicit operator bool() const { return !!m_callableWrapper; }
 
-    template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type>
+    template<typename CallableType, class = typename std::enable_if<!(std::is_pointer<CallableType>::value && std::is_function<typename std::remove_pointer<CallableType>::type>::value) && std::is_rvalue_reference<CallableType&&>::value>::type>
     Function& operator=(CallableType&& callable)
     {
         m_callableWrapper = std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable));
index cce1106..aacc7cc 100644 (file)
@@ -93,8 +93,22 @@ bool ParallelEnvironment::ThreadPrivate::tryLockFor(ParallelEnvironment* parent)
         return false;
     }
 
-    if (!m_thread)
-        m_thread = Thread::create(&ParallelEnvironment::ThreadPrivate::workerThread, this, "Parallel worker");
+    if (!m_thread) {
+        m_thread = Thread::create("Parallel worker", [this] {
+            LockHolder lock(m_mutex);
+
+            while (m_thread) {
+                if (m_running) {
+                    (*m_threadFunction)(m_parameters);
+                    m_running = false;
+                    m_parent = 0;
+                    m_threadCondition.notifyOne();
+                }
+
+                m_threadCondition.wait(m_mutex);
+            }
+        });
+    }
 
     if (m_thread)
         m_parent = parent;
@@ -121,22 +135,5 @@ void ParallelEnvironment::ThreadPrivate::waitForFinish()
         m_threadCondition.wait(m_mutex);
 }
 
-void ParallelEnvironment::ThreadPrivate::workerThread(void* threadData)
-{
-    ThreadPrivate* sharedThread = reinterpret_cast<ThreadPrivate*>(threadData);
-    LockHolder lock(sharedThread->m_mutex);
-
-    while (sharedThread->m_thread) {
-        if (sharedThread->m_running) {
-            (*sharedThread->m_threadFunction)(sharedThread->m_parameters);
-            sharedThread->m_running = false;
-            sharedThread->m_parent = 0;
-            sharedThread->m_threadCondition.notifyOne();
-        }
-
-        sharedThread->m_threadCondition.wait(sharedThread->m_mutex);
-    }
-}
-
 } // namespace WTF
 #endif // ENABLE(THREADING_GENERIC)
index a20cab6..7f7080c 100644 (file)
@@ -64,8 +64,6 @@ public:
             return adoptRef(*new ThreadPrivate());
         }
 
-        static void workerThread(void*);
-
     private:
         RefPtr<Thread> m_thread;
         bool m_running { false };
index 7896e9c..ddc28c2 100644 (file)
@@ -111,13 +111,6 @@ RefPtr<Thread> Thread::create(const char* name, Function<void()>&& entryPoint)
     return Thread::createInternal(threadEntryPoint, context, name);
 }
 
-RefPtr<Thread> Thread::create(ThreadFunction entryPoint, void* data, const char* name)
-{
-    return Thread::create(name, [entryPoint, data] {
-        entryPoint(data);
-    });
-}
-
 void Thread::didExit()
 {
     std::unique_lock<std::mutex> locker(m_mutex);
index 5d5b162..bd615fb 100644 (file)
@@ -516,7 +516,9 @@ DWORD absoluteTimeToWaitTimeoutInterval(double absoluteTime)
 // Remove this workaround code when <rdar://problem/31793213> is fixed.
 ThreadIdentifier createThread(ThreadFunction function, void* data, const char* threadName)
 {
-    return Thread::create(function, data, threadName)->id();
+    return Thread::create(threadName, [function, data] {
+        function(data);
+    })->id();
 }
 
 int waitForThreadCompletion(ThreadIdentifier threadID)
index 6cf700a..a52a8a1 100644 (file)
@@ -1,3 +1,66 @@
+2017-06-26  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Drop Thread::create(obsolete things) API since we can use lambda
+        https://bugs.webkit.org/show_bug.cgi?id=173825
+
+        Reviewed by Saam Barati.
+
+        No behavior change.
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::IDBServer):
+        (WebCore::IDBServer::IDBServer::databaseThreadEntry): Deleted.
+        * Modules/indexeddb/server/IDBServer.h:
+        * Modules/webaudio/AsyncAudioDecoder.cpp:
+        (WebCore::AsyncAudioDecoder::AsyncAudioDecoder):
+        (WebCore::AsyncAudioDecoder::threadEntry): Deleted.
+        * Modules/webaudio/AsyncAudioDecoder.h:
+        * Modules/webaudio/OfflineAudioDestinationNode.cpp:
+        (WebCore::OfflineAudioDestinationNode::startRendering):
+        (WebCore::OfflineAudioDestinationNode::offlineRenderEntry): Deleted.
+        * Modules/webaudio/OfflineAudioDestinationNode.h:
+        * Modules/webdatabase/DatabaseThread.cpp:
+        (WebCore::DatabaseThread::start):
+        (WebCore::DatabaseThread::databaseThreadStart): Deleted.
+        * Modules/webdatabase/DatabaseThread.h:
+        * bindings/js/GCController.cpp:
+        (WebCore::collect):
+        (WebCore::GCController::gcTimerFired):
+        (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging):
+        * loader/icon/IconDatabase.cpp:
+        (WebCore::IconDatabase::open):
+        (WebCore::IconDatabase::iconDatabaseSyncThreadStart): Deleted.
+        * loader/icon/IconDatabase.h:
+        * page/ResourceUsageThread.cpp:
+        (WebCore::ResourceUsageThread::createThreadIfNeeded):
+        (WebCore::ResourceUsageThread::threadCallback): Deleted.
+        * page/ResourceUsageThread.h:
+        * page/scrolling/ScrollingThread.cpp:
+        (WebCore::ScrollingThread::createThreadIfNeeded):
+        (WebCore::ScrollingThread::threadCallback): Deleted.
+        (WebCore::ScrollingThread::threadBody): Deleted.
+        * page/scrolling/ScrollingThread.h:
+        * platform/audio/HRTFDatabaseLoader.cpp:
+        (WebCore::HRTFDatabaseLoader::loadAsynchronously):
+        (WebCore::databaseLoaderEntry): Deleted.
+        * platform/audio/HRTFDatabaseLoader.h:
+        * platform/audio/ReverbConvolver.cpp:
+        (WebCore::ReverbConvolver::ReverbConvolver):
+        (WebCore::backgroundThreadEntry): Deleted.
+        * platform/audio/ReverbConvolver.h:
+        (WebCore::ReverbConvolver::useBackgroundThreads):
+        * platform/network/cf/LoaderRunLoopCF.cpp:
+        (WebCore::loaderRunLoop):
+        (WebCore::runLoaderThread): Deleted.
+        * platform/network/curl/CurlManager.cpp:
+        (WebCore::CurlManager::startThreadIfNeeded):
+        (WebCore::CurlManager::workerThread):
+        * platform/network/curl/CurlManager.h:
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerThread::start):
+        (WebCore::WorkerThread::workerThreadStart): Deleted.
+        * workers/WorkerThread.h:
+
 2017-06-26  Joanmarie Diggs  <jdiggs@igalia.com>
 
         [ATK] Add support for aria-details and aria-errormessage
index 6443ddc..420c3a6 100644 (file)
@@ -56,7 +56,9 @@ IDBServer::IDBServer(IDBBackingStoreTemporaryFileHandler& fileHandler)
     : m_backingStoreTemporaryFileHandler(fileHandler)
 {
     Locker<Lock> locker(m_databaseThreadCreationLock);
-    m_thread = Thread::create(IDBServer::databaseThreadEntry, this, "IndexedDatabase Server");
+    m_thread = Thread::create("IndexedDatabase Server", [this] {
+        databaseRunLoop();
+    });
 }
 
 IDBServer::IDBServer(const String& databaseDirectoryPath, IDBBackingStoreTemporaryFileHandler& fileHandler)
@@ -66,7 +68,9 @@ IDBServer::IDBServer(const String& databaseDirectoryPath, IDBBackingStoreTempora
     LOG(IndexedDB, "IDBServer created at path %s", databaseDirectoryPath.utf8().data());
 
     Locker<Lock> locker(m_databaseThreadCreationLock);
-    m_thread = Thread::create(IDBServer::databaseThreadEntry, this, "IndexedDatabase Server");
+    m_thread = Thread::create("IndexedDatabase Server", [this] {
+        databaseRunLoop();
+    });
 }
 
 void IDBServer::registerConnection(IDBConnectionToClient& connection)
@@ -500,13 +504,6 @@ void IDBServer::postDatabaseTaskReply(CrossThreadTask&& task)
     });
 }
 
-void IDBServer::databaseThreadEntry(void* threadData)
-{
-    ASSERT(threadData);
-    IDBServer* server = reinterpret_cast<IDBServer*>(threadData);
-    server->databaseRunLoop();
-}
-
 void IDBServer::databaseRunLoop()
 {
     ASSERT(!isMainThread());
index e46f7b5..db10d69 100644 (file)
@@ -118,7 +118,6 @@ private:
     void performCloseAndDeleteDatabasesForOrigins(const Vector<SecurityOriginData>&, uint64_t callbackID);
     void didPerformCloseAndDeleteDatabases(uint64_t callbackID);
 
-    static void databaseThreadEntry(void*);
     void databaseRunLoop();
     void handleTaskRepliesOnMainThread();
 
index 7cf7af8..1150157 100644 (file)
@@ -39,7 +39,9 @@ AsyncAudioDecoder::AsyncAudioDecoder()
 {
     // Start worker thread.
     LockHolder lock(m_threadCreationMutex);
-    m_thread = Thread::create(AsyncAudioDecoder::threadEntry, this, "Audio Decoder");
+    m_thread = Thread::create("Audio Decoder", [this] {
+        runLoop();
+    });
 }
 
 AsyncAudioDecoder::~AsyncAudioDecoder()
@@ -59,14 +61,6 @@ void AsyncAudioDecoder::decodeAsync(Ref<ArrayBuffer>&& audioData, float sampleRa
     m_queue.append(WTFMove(decodingTask)); // note that ownership of the task is effectively taken by the queue.
 }
 
-// Asynchronously decode in this thread.
-void AsyncAudioDecoder::threadEntry(void* threadData)
-{
-    ASSERT(threadData);
-    AsyncAudioDecoder* decoder = reinterpret_cast<AsyncAudioDecoder*>(threadData);
-    decoder->runLoop();
-}
-
 void AsyncAudioDecoder::runLoop()
 {
     ASSERT(!isMainThread());
index f12510d..42fc002 100644 (file)
@@ -74,7 +74,6 @@ private:
         RefPtr<AudioBuffer> m_audioBuffer;
     };
     
-    static void threadEntry(void* threadData);
     void runLoop();
 
     RefPtr<Thread> m_thread;
index 37b9588..e995b08 100644 (file)
@@ -82,18 +82,12 @@ void OfflineAudioDestinationNode::startRendering()
     if (!m_startedRendering) {
         m_startedRendering = true;
         ref(); // See corresponding deref() call in notifyCompleteDispatch().
-        m_renderThread = Thread::create(OfflineAudioDestinationNode::offlineRenderEntry, this, "offline renderer");
+        m_renderThread = Thread::create("offline renderer", [this] {
+            offlineRender();
+        });
     }
 }
 
-// Do offline rendering in this thread.
-void OfflineAudioDestinationNode::offlineRenderEntry(void* threadData)
-{
-    OfflineAudioDestinationNode* destinationNode = reinterpret_cast<OfflineAudioDestinationNode*>(threadData);
-    ASSERT(destinationNode);
-    destinationNode->offlineRender();
-}
-
 void OfflineAudioDestinationNode::offlineRender()
 {
     ASSERT(!isMainThread());
index 5690138..b945bef 100644 (file)
@@ -65,7 +65,6 @@ private:
     // Rendering thread.
     RefPtr<Thread> m_renderThread;
     bool m_startedRendering;
-    static void offlineRenderEntry(void* threadData);
     void offlineRender();
     
     // For completion callback on main thread.
index d70814f..11524cd 100644 (file)
@@ -63,7 +63,9 @@ bool DatabaseThread::start()
     if (m_thread)
         return true;
 
-    m_thread = Thread::create(DatabaseThread::databaseThreadStart, this, "WebCore: Database");
+    m_thread = Thread::create("WebCore: Database", [this] {
+        databaseThread();
+    });
 
     return m_thread;
 }
@@ -87,12 +89,6 @@ bool DatabaseThread::terminationRequested(DatabaseTaskSynchronizer* taskSynchron
     return m_queue.killed();
 }
 
-void DatabaseThread::databaseThreadStart(void* vDatabaseThread)
-{
-    DatabaseThread* dbThread = static_cast<DatabaseThread*>(vDatabaseThread);
-    dbThread->databaseThread();
-}
-
 void DatabaseThread::databaseThread()
 {
     {
index 0e7a000..34009d1 100644 (file)
@@ -65,7 +65,6 @@ public:
 private:
     DatabaseThread();
 
-    static void databaseThreadStart(void*);
     void databaseThread();
 
     Lock m_threadCreationMutex;
index 5ae3972..b26f757 100644 (file)
@@ -38,7 +38,7 @@ using namespace JSC;
 
 namespace WebCore {
 
-static void collect(void*)
+static void collect()
 {
     JSLockHolder lock(commonVM());
     commonVM().heap.collectNow(Async, CollectionScope::Full);
@@ -76,7 +76,7 @@ void GCController::garbageCollectOnNextRunLoop()
 
 void GCController::gcTimerFired()
 {
-    collect(nullptr);
+    collect();
 }
 
 void GCController::garbageCollectNow()
@@ -101,7 +101,7 @@ void GCController::garbageCollectNowIfNotDoneRecently()
 
 void GCController::garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone)
 {
-    RefPtr<Thread> thread = Thread::create(collect, 0, "WebCore: GCController");
+    RefPtr<Thread> thread = Thread::create("WebCore: GCController", &collect);
 
     if (waitUntilDone) {
         thread->waitForCompletion();
index 48f88c5..598c939 100644 (file)
@@ -141,7 +141,9 @@ bool IconDatabase::open(const String& directory, const String& filename)
     // Lock here as well as first thing in the thread so the thread doesn't actually commence until the createThread() call 
     // completes and m_syncThreadRunning is properly set
     m_syncLock.lock();
-    m_syncThread = Thread::create(IconDatabase::iconDatabaseSyncThreadStart, this, "WebCore: IconDatabase");
+    m_syncThread = Thread::create("WebCore: IconDatabase", [this] {
+        iconDatabaseSyncThread();
+    });
     m_syncThreadRunning = m_syncThread;
     m_syncLock.unlock();
     if (!m_syncThread)
@@ -942,13 +944,6 @@ bool IconDatabase::shouldStopThreadActivity() const
     return m_threadTerminationRequested || m_removeIconsRequested;
 }
 
-void IconDatabase::iconDatabaseSyncThreadStart(void* vIconDatabase)
-{    
-    IconDatabase* iconDB = static_cast<IconDatabase*>(vIconDatabase);
-    
-    iconDB->iconDatabaseSyncThread();
-}
-
 void IconDatabase::iconDatabaseSyncThread()
 {
     // The call to create this thread might not complete before the thread actually starts, so we might fail this ASSERT_ICON_SYNC_THREAD() because the pointer 
index 8640955..0040b42 100644 (file)
@@ -182,7 +182,6 @@ public:
     WEBCORE_EXPORT bool shouldStopThreadActivity() const final;
 
 private:    
-    static void iconDatabaseSyncThreadStart(void *);
     void iconDatabaseSyncThread();
     
     // The following block of methods are called exclusively by the sync thread to manage i/o to and from the database
index e0b2784..bb694bd 100644 (file)
@@ -100,12 +100,9 @@ void ResourceUsageThread::createThreadIfNeeded()
         return;
 
     m_vm = &commonVM();
-    m_thread = Thread::create(threadCallback, this, "WebCore: ResourceUsage");
-}
-
-void ResourceUsageThread::threadCallback(void* resourceUsageThread)
-{
-    static_cast<ResourceUsageThread*>(resourceUsageThread)->threadBody();
+    m_thread = Thread::create("WebCore: ResourceUsage", [this] {
+        threadBody();
+    });
 }
 
 NO_RETURN void ResourceUsageThread::threadBody()
index 3617b7a..824b648 100644 (file)
@@ -58,7 +58,6 @@ private:
     void notifyObservers(ResourceUsageData&&);
 
     void createThreadIfNeeded();
-    static void threadCallback(void* scrollingThread);
     void threadBody();
     void platformThreadBody(JSC::VM*, ResourceUsageData&);
 
index 64d050a..d204c76 100644 (file)
@@ -80,7 +80,10 @@ void ScrollingThread::createThreadIfNeeded()
     {
         std::unique_lock<Lock> lock(m_initializeRunLoopMutex);
 
-        m_thread = Thread::create(threadCallback, this, "WebCore: Scrolling");
+        m_thread = Thread::create("WebCore: Scrolling", [this] {
+            WTF::Thread::setCurrentThreadIsUserInteractive();
+            initializeRunLoop();
+        });
         
 #if PLATFORM(COCOA)
         m_initializeRunLoopConditionVariable.wait(lock, [this]{ return m_threadRunLoop; });
@@ -88,17 +91,6 @@ void ScrollingThread::createThreadIfNeeded()
     }
 }
 
-void ScrollingThread::threadCallback(void* scrollingThread)
-{
-    WTF::Thread::setCurrentThreadIsUserInteractive();
-    static_cast<ScrollingThread*>(scrollingThread)->threadBody();
-}
-
-void ScrollingThread::threadBody()
-{
-    initializeRunLoop();
-}
-
 void ScrollingThread::dispatchFunctionsFromScrollingThread()
 {
     ASSERT(isCurrentThread());
index d8892f0..7e81d08 100644 (file)
@@ -61,8 +61,6 @@ private:
     static ScrollingThread& singleton();
 
     void createThreadIfNeeded();
-    static void threadCallback(void* scrollingThread);
-    void threadBody();
     void dispatchFunctionsFromScrollingThread();
 
     void initializeRunLoop();
index e574ea8..f45be84 100644 (file)
@@ -80,14 +80,6 @@ HRTFDatabaseLoader::~HRTFDatabaseLoader()
     loaderMap().remove(m_databaseSampleRate);
 }
 
-// Asynchronously load the database in this thread.
-static void databaseLoaderEntry(void* threadData)
-{
-    HRTFDatabaseLoader* loader = reinterpret_cast<HRTFDatabaseLoader*>(threadData);
-    ASSERT(loader);
-    loader->load();
-}
-
 void HRTFDatabaseLoader::load()
 {
     ASSERT(!isMainThread());
@@ -105,7 +97,9 @@ void HRTFDatabaseLoader::loadAsynchronously()
     
     if (!m_hrtfDatabase.get() && !m_databaseLoaderThread) {
         // Start the asynchronous database loading process.
-        m_databaseLoaderThread = Thread::create(databaseLoaderEntry, this, "HRTF database loader");
+        m_databaseLoaderThread = Thread::create("HRTF database loader", [this] {
+            load();
+        });
     }
 }
 
index d0be8e7..1ff4962 100644 (file)
@@ -61,9 +61,6 @@ public:
 
     float databaseSampleRate() const { return m_databaseSampleRate; }
     
-    // Called in asynchronous loading thread.
-    void load();
-
 private:
     // Both constructor and destructor must be called from the main thread.
     explicit HRTFDatabaseLoader(float sampleRate);
@@ -72,6 +69,9 @@ private:
     // This must be called from the main thread.
     void loadAsynchronously();
 
+    // Called in asynchronous loading thread.
+    void load();
+
     std::unique_ptr<HRTFDatabase> m_hrtfDatabase;
 
     // Holding a m_threadLock is required when accessing m_databaseLoaderThread.
index 21be996..0e74661 100644 (file)
@@ -54,12 +54,6 @@ const size_t RealtimeFrameLimit = 8192  + 4096; // ~278msec @ 44.1KHz
 const size_t MinFFTSize = 128;
 const size_t MaxRealtimeFFTSize = 2048;
 
-static void backgroundThreadEntry(void* threadData)
-{
-    ReverbConvolver* reverbConvolver = static_cast<ReverbConvolver*>(threadData);
-    reverbConvolver->backgroundThreadEntry();
-}
-
 ReverbConvolver::ReverbConvolver(AudioChannel* impulseResponse, size_t renderSliceSize, size_t maxFFTSize, size_t convolverRenderPhase, bool useBackgroundThreads)
     : m_impulseResponseLength(impulseResponse->length())
     , m_accumulationBuffer(impulseResponse->length() + renderSliceSize)
@@ -129,8 +123,11 @@ ReverbConvolver::ReverbConvolver(AudioChannel* impulseResponse, size_t renderSli
 
     // Start up background thread
     // FIXME: would be better to up the thread priority here.  It doesn't need to be real-time, but higher than the default...
-    if (this->useBackgroundThreads() && m_backgroundStages.size() > 0)
-        m_backgroundThread = Thread::create(WebCore::backgroundThreadEntry, this, "convolution background thread");
+    if (this->useBackgroundThreads() && m_backgroundStages.size() > 0) {
+        m_backgroundThread = Thread::create("convolution background thread", [this] {
+            backgroundThreadEntry();
+        });
+    }
 }
 
 ReverbConvolver::~ReverbConvolver()
index 1fccf96..8ac6eec 100644 (file)
@@ -60,10 +60,11 @@ public:
     ReverbInputBuffer* inputBuffer() { return &m_inputBuffer; }
 
     bool useBackgroundThreads() const { return m_useBackgroundThreads; }
-    void backgroundThreadEntry();
 
     size_t latencyFrames() const;
 private:
+    void backgroundThreadEntry();
+
     Vector<std::unique_ptr<ReverbConvolverStage>> m_stages;
     Vector<std::unique_ptr<ReverbConvolverStage>> m_backgroundStages;
     size_t m_impulseResponseLength;
index ffbfda9..f08327f 100644 (file)
@@ -48,28 +48,6 @@ static void emptyPerform(void*)
 {
 }
 
-static void runLoaderThread(void*)
-{
-    {
-        std::lock_guard<StaticLock> lock(loaderRunLoopMutex);
-
-        loaderRunLoopObject = CFRunLoopGetCurrent();
-
-        // Must add a source to the run loop to prevent CFRunLoopRun() from exiting.
-        CFRunLoopSourceContext ctxt = {0, (void*)1 /*must be non-null*/, 0, 0, 0, 0, 0, 0, 0, emptyPerform};
-        CFRunLoopSourceRef bogusSource = CFRunLoopSourceCreate(0, 0, &ctxt);
-        CFRunLoopAddSource(loaderRunLoopObject, bogusSource, kCFRunLoopDefaultMode);
-
-        loaderRunLoopConditionVariable.notifyOne();
-    }
-
-    SInt32 result;
-    do {
-        AutodrainedPool pool;
-        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, std::numeric_limits<double>::max(), true);
-    } while (result != kCFRunLoopRunStopped && result != kCFRunLoopRunFinished);
-}
-
 CFRunLoopRef loaderRunLoop()
 {
     ASSERT(isMainThread());
@@ -77,7 +55,26 @@ CFRunLoopRef loaderRunLoop()
     std::unique_lock<StaticLock> lock(loaderRunLoopMutex);
 
     if (!loaderRunLoopObject) {
-        Thread::create(runLoaderThread, 0, "WebCore: CFNetwork Loader");
+        Thread::create("WebCore: CFNetwork Loader", [] {
+            {
+                std::lock_guard<StaticLock> lock(loaderRunLoopMutex);
+
+                loaderRunLoopObject = CFRunLoopGetCurrent();
+
+                // Must add a source to the run loop to prevent CFRunLoopRun() from exiting.
+                CFRunLoopSourceContext ctxt = {0, (void*)1 /*must be non-null*/, 0, 0, 0, 0, 0, 0, 0, emptyPerform};
+                CFRunLoopSourceRef bogusSource = CFRunLoopSourceCreate(0, 0, &ctxt);
+                CFRunLoopAddSource(loaderRunLoopObject, bogusSource, kCFRunLoopDefaultMode);
+
+                loaderRunLoopConditionVariable.notifyOne();
+            }
+
+            SInt32 result;
+            do {
+                AutodrainedPool pool;
+                result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, std::numeric_limits<double>::max(), true);
+            } while (result != kCFRunLoopRunStopped && result != kCFRunLoopRunFinished);
+        });
 
         loaderRunLoopConditionVariable.wait(lock, [] { return loaderRunLoopObject; });
     }
index 8f2eef6..059ffe2 100644 (file)
@@ -109,7 +109,9 @@ void CurlManager::startThreadIfNeeded()
         if (m_thread)
             m_thread->waitForCompletion();
         setRunThread(true);
-        m_thread = Thread::create(workerThread, this, "curlThread");
+        m_thread = Thread::create("curlThread", [this] {
+            workerThread();
+        });
     }
 }
 
@@ -176,15 +178,13 @@ bool CurlManager::removeFromCurl(CURL* curlHandle)
     return false;
 }
 
-void CurlManager::workerThread(void* data)
+void CurlManager::workerThread()
 {
     ASSERT(!isMainThread());
 
-    CurlManager* manager = reinterpret_cast<CurlManager*>(data);
+    while (runThread()) {
 
-    while (manager->runThread()) {
-
-        manager->updateHandleList();
+        updateHandleList();
 
         // Retry 'select' if it was interrupted by a process signal.
         int rc = 0;
@@ -204,7 +204,7 @@ void CurlManager::workerThread(void* data)
             FD_ZERO(&fdread);
             FD_ZERO(&fdwrite);
             FD_ZERO(&fdexcep);
-            curl_multi_fdset(manager->getMultiHandle(), &fdread, &fdwrite, &fdexcep, &maxfd);
+            curl_multi_fdset(getMultiHandle(), &fdread, &fdwrite, &fdexcep, &maxfd);
             // When the 3 file descriptors are empty, winsock will return -1
             // and bail out, stopping the file download. So make sure we
             // have valid file descriptors before calling select.
@@ -213,10 +213,10 @@ void CurlManager::workerThread(void* data)
         } while (rc == -1 && errno == EINTR);
 
         int activeCount = 0;
-        while (curl_multi_perform(manager->getMultiHandle(), &activeCount) == CURLM_CALL_MULTI_PERFORM) { }
+        while (curl_multi_perform(getMultiHandle(), &activeCount) == CURLM_CALL_MULTI_PERFORM) { }
 
         int messagesInQueue = 0;
-        CURLMsg* msg = curl_multi_info_read(manager->getMultiHandle(), &messagesInQueue);
+        CURLMsg* msg = curl_multi_info_read(getMultiHandle(), &messagesInQueue);
 
         if (!msg)
             continue;
@@ -230,9 +230,9 @@ void CurlManager::workerThread(void* data)
         CurlJobAction action = job->handleCurlMsg(msg);
 
         if (action == CurlJobAction::Finished)
-            manager->removeFromCurl(msg->easy_handle);
+            removeFromCurl(msg->easy_handle);
 
-        manager->stopThreadIfIdle();
+        stopThreadIfIdle();
     }
 }
 
index 9523d4c..5482ec1 100644 (file)
@@ -84,7 +84,7 @@ private:
     bool addToCurl(CURL* curlHandle);
     bool removeFromCurl(CURL* curlHandle);
 
-    static void workerThread(void* data);
+    void workerThread();
 
     RefPtr<Thread> m_thread;
     CURLM* m_curlMultiHandle { nullptr };
index 35a2382..425c924 100644 (file)
@@ -138,16 +138,13 @@ bool WorkerThread::start()
     if (m_thread)
         return true;
 
-    m_thread = Thread::create(WorkerThread::workerThreadStart, this, "WebCore: Worker");
+    m_thread = Thread::create("WebCore: Worker", [this] {
+        workerThread();
+    });
 
     return m_thread;
 }
 
-void WorkerThread::workerThreadStart(void* thread)
-{
-    static_cast<WorkerThread*>(thread)->workerThread();
-}
-
 void WorkerThread::workerThread()
 {
     // Propagate the mainThread's fenv to workers.
index 29f4d98..22908a8 100644 (file)
@@ -94,8 +94,6 @@ protected:
     SocketProvider* socketProvider();
 
 private:
-    // Static function executed as the core routine on the new thread. Passed a pointer to a WorkerThread object.
-    static void workerThreadStart(void*);
     void workerThread();
 
     RefPtr<Thread> m_thread;
index 7f0fcfd..21b2d3f 100644 (file)
@@ -1,3 +1,15 @@
+2017-06-26  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Drop Thread::create(obsolete things) API since we can use lambda
+        https://bugs.webkit.org/show_bug.cgi?id=173825
+
+        Reviewed by Saam Barati.
+
+        * Storage/StorageThread.cpp:
+        (WebCore::StorageThread::start):
+        (WebCore::StorageThread::threadEntryPointCallback): Deleted.
+        * Storage/StorageThread.h:
+
 2017-06-16  Alex Christensen  <achristensen@webkit.org>
 
         Fix Visual Studio 2017 64-bit build after r218258
index f3cbed3..9b50907 100644 (file)
@@ -53,17 +53,15 @@ StorageThread::~StorageThread()
 bool StorageThread::start()
 {
     ASSERT(isMainThread());
-    if (!m_thread)
-        m_thread = Thread::create(StorageThread::threadEntryPointCallback, this, "WebCore: LocalStorage");
+    if (!m_thread) {
+        m_thread = Thread::create("WebCore: LocalStorage", [this] {
+            threadEntryPoint();
+        });
+    }
     activeStorageThreads().add(this);
     return m_thread;
 }
 
-void StorageThread::threadEntryPointCallback(void* thread)
-{
-    static_cast<StorageThread*>(thread)->threadEntryPoint();
-}
-
 void StorageThread::threadEntryPoint()
 {
     ASSERT(!isMainThread());
index 8cf1b3d..aded230 100644 (file)
@@ -49,8 +49,6 @@ public:
     static void releaseFastMallocFreeMemoryInAllThreads();
 
 private:
-    // Called on background thread.
-    static void threadEntryPointCallback(void*);
     void threadEntryPoint();
 
     // Background thread part of the terminate procedure.
index bf24c8b..a2cb977 100644 (file)
@@ -1,3 +1,18 @@
+2017-06-26  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Drop Thread::create(obsolete things) API since we can use lambda
+        https://bugs.webkit.org/show_bug.cgi?id=173825
+
+        Reviewed by Saam Barati.
+
+        * DumpRenderTree/JavaScriptThreading.cpp:
+        (runJavaScriptThread):
+        (startJavaScriptThreads):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (runThread):
+        (runPthread):
+        (testThreadIdentifierMap):
+
 2017-06-26  David Kilzer  <ddkilzer@apple.com>
 
         [TestWebKitAPI] Fix false-positive bad release warnings found by clang static analyzer
index 710d2a5..2eafbbe 100644 (file)
@@ -61,7 +61,7 @@ static ThreadSet& javaScriptThreads()
 
 // This function exercises JSC in a loop until javaScriptThreadsShouldTerminate
 // becomes true or it probabilistically decides to spawn a replacement thread and exit.
-void runJavaScriptThread(void*)
+void runJavaScriptThread()
 {
     static const char* const script =
         "var array = [];"
@@ -111,7 +111,7 @@ void runJavaScriptThread(void*)
         Thread& thread = Thread::current();
         thread.detach();
         javaScriptThreads().remove(&thread);
-        javaScriptThreads().add(Thread::create(&runJavaScriptThread, 0, 0));
+        javaScriptThreads().add(Thread::create("JavaScript Thread", &runJavaScriptThread));
         break;
     }
 
@@ -128,7 +128,7 @@ void startJavaScriptThreads()
     LockHolder locker(javaScriptThreadsMutex());
 
     for (size_t i = 0; i < javaScriptThreadsCount; ++i)
-        javaScriptThreads().add(Thread::create(&runJavaScriptThread, 0, 0));
+        javaScriptThreads().add(Thread::create("JavaScript Thread", &runJavaScriptThread));
 }
 
 void stopJavaScriptThreads()
index 523f3f3..280eb7e 100644 (file)
@@ -1052,7 +1052,7 @@ static void setDefaultsToConsistentValuesForTesting()
     [[NSUserDefaults standardUserDefaults] setVolatileDomain:processInstanceDefaults forName:NSArgumentDomain];
 }
 
-static void runThread(void* arg)
+static void runThread()
 {
     static ThreadIdentifier previousId = 0;
     ThreadIdentifier currentId = currentThread();
@@ -1061,10 +1061,10 @@ static void runThread(void* arg)
     previousId = currentId;
 }
 
-static void* runPthread(void* arg)
+static void* runPthread(void*)
 {
-    runThread(arg);
-    return 0;
+    runThread();
+    return nullptr;
 }
 
 static void testThreadIdentifierMap()
@@ -1079,7 +1079,7 @@ static void testThreadIdentifierMap()
 
     // Now create another thread using WTF. On OSX, it will have the same pthread handle
     // but should get a different RefPtr<Thread>.
-    Thread::create(runThread, 0, "DumpRenderTree: test");
+    Thread::create("DumpRenderTree: test", runThread);
 }
 
 static void allocateGlobalControllers()