Drop unnecessary "ServiceWorker Task Thread" in SWServer
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jan 2018 19:45:30 +0000 (19:45 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jan 2018 19:45:30 +0000 (19:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182253

Reviewed by Youenn Fablet.

Drop unnecessary "ServiceWorker Task Thread" in SWServer. We're spinning a thread for
each SWServer that is never used.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::~SWServer):
(WebCore::SWServer::SWServer):
(WebCore::SWServer::taskThreadEntryPoint): Deleted.
(WebCore::SWServer::postTask): Deleted.
(WebCore::SWServer::postTaskReply): Deleted.
(WebCore::SWServer::handleTaskRepliesOnMainThread): Deleted.
* workers/service/server/SWServer.h:

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

Source/WebCore/ChangeLog
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h

index b2f8b25..97d87b2 100644 (file)
@@ -1,3 +1,22 @@
+2018-01-29  Chris Dumez  <cdumez@apple.com>
+
+        Drop unnecessary "ServiceWorker Task Thread" in SWServer
+        https://bugs.webkit.org/show_bug.cgi?id=182253
+
+        Reviewed by Youenn Fablet.
+
+        Drop unnecessary "ServiceWorker Task Thread" in SWServer. We're spinning a thread for
+        each SWServer that is never used.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::~SWServer):
+        (WebCore::SWServer::SWServer):
+        (WebCore::SWServer::taskThreadEntryPoint): Deleted.
+        (WebCore::SWServer::postTask): Deleted.
+        (WebCore::SWServer::postTaskReply): Deleted.
+        (WebCore::SWServer::handleTaskRepliesOnMainThread): Deleted.
+        * workers/service/server/SWServer.h:
+
 2018-01-29  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r227731.
index b3231f5..6206d58 100644 (file)
@@ -73,15 +73,6 @@ SWServer::~SWServer()
     RELEASE_ASSERT(m_connections.isEmpty());
     RELEASE_ASSERT(m_registrations.isEmpty());
     RELEASE_ASSERT(m_jobQueues.isEmpty());
-
-    ASSERT(m_taskQueue.isEmpty());
-    ASSERT(m_taskReplyQueue.isEmpty());
-
-    // For a SWServer to be cleanly shut down its thread must have finished and gone away.
-    // At this stage in development of the feature that actually never happens.
-    // But once it does start happening, this ASSERT will catch us doing it wrong.
-    Locker<Lock> locker(m_taskThreadLock);
-    ASSERT(!m_taskThread);
     
     allServers().remove(this);
 }
@@ -271,9 +262,6 @@ SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, String&& registration
 {
     UNUSED_PARAM(registrationDatabaseDirectory);
     allServers().add(this);
-    m_taskThread = Thread::create(ASCIILiteral("ServiceWorker Task Thread"), [this] {
-        taskThreadEntryPoint();
-    });
 }
 
 // https://w3c.github.io/ServiceWorker/#schedule-job-algorithm
@@ -678,47 +666,6 @@ void SWServer::fireActivateEvent(SWServerWorker& worker)
     connection->fireActivateEvent(worker.identifier());
 }
 
-void SWServer::taskThreadEntryPoint()
-{
-    ASSERT(!isMainThread());
-
-    while (!m_taskQueue.isKilled())
-        m_taskQueue.waitForMessage().performTask();
-
-    Locker<Lock> locker(m_taskThreadLock);
-    m_taskThread = nullptr;
-}
-
-void SWServer::postTask(CrossThreadTask&& task)
-{
-    m_taskQueue.append(WTFMove(task));
-}
-
-void SWServer::postTaskReply(CrossThreadTask&& task)
-{
-    m_taskReplyQueue.append(WTFMove(task));
-
-    Locker<Lock> locker(m_mainThreadReplyLock);
-    if (m_mainThreadReplyScheduled)
-        return;
-
-    m_mainThreadReplyScheduled = true;
-    callOnMainThread([this] {
-        handleTaskRepliesOnMainThread();
-    });
-}
-
-void SWServer::handleTaskRepliesOnMainThread()
-{
-    {
-        Locker<Lock> locker(m_mainThreadReplyLock);
-        m_mainThreadReplyScheduled = false;
-    }
-
-    while (auto task = m_taskReplyQueue.tryGetMessage())
-        task->performTask();
-}
-
 void SWServer::registerConnection(Connection& connection)
 {
     auto result = m_connections.add(connection.identifier(), nullptr);
index ffc1e59..86bb32c 100644 (file)
@@ -37,8 +37,6 @@
 #include "ServiceWorkerRegistrationData.h"
 #include "ServiceWorkerRegistrationKey.h"
 #include "ServiceWorkerTypes.h"
-#include <wtf/CrossThreadQueue.h>
-#include <wtf/CrossThreadTask.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/ObjectIdentifier.h>
@@ -137,9 +135,6 @@ public:
     void resolveUnregistrationJob(const ServiceWorkerJobData&, const ServiceWorkerRegistrationKey&, bool unregistrationResult);
     void startScriptFetch(const ServiceWorkerJobData&, FetchOptions::Cache);
 
-    void postTask(CrossThreadTask&&);
-    void postTaskReply(CrossThreadTask&&);
-
     void updateWorker(Connection&, const ServiceWorkerJobDataIdentifier&, SWServerRegistration&, const URL&, const String& script, const ContentSecurityPolicyResponseHeaders&, WorkerType);
     void terminateWorker(SWServerWorker&);
     void syncTerminateWorker(SWServerWorker&);
@@ -186,9 +181,6 @@ private:
     void registerConnection(Connection&);
     void unregisterConnection(Connection&);
 
-    void taskThreadEntryPoint();
-    void handleTaskRepliesOnMainThread();
-
     void scriptFetchFinished(Connection&, const ServiceWorkerFetchResult&);
 
     void didResolveRegistrationPromise(Connection&, const ServiceWorkerRegistrationKey&);
@@ -228,14 +220,6 @@ private:
     HashMap<ServiceWorkerClientIdentifier, ServiceWorkerClientData> m_clientsById;
     HashMap<ServiceWorkerClientIdentifier, ServiceWorkerIdentifier> m_clientToControllingWorker;
 
-    RefPtr<Thread> m_taskThread;
-    Lock m_taskThreadLock;
-
-    CrossThreadQueue<CrossThreadTask> m_taskQueue;
-    CrossThreadQueue<CrossThreadTask> m_taskReplyQueue;
-
-    Lock m_mainThreadReplyLock;
-    bool m_mainThreadReplyScheduled { false };
     UniqueRef<SWOriginStore> m_originStore;
     RegistrationStore m_registrationStore;
     Vector<ServiceWorkerContextData> m_pendingContextDatas;