Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1327)

Unified Diff: Source/core/workers/WorkerThread.cpp

Issue 441063003: Run microtasks at the end of each worker task. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/workers/WorkerThread.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/workers/WorkerThread.cpp
diff --git a/Source/core/workers/WorkerThread.cpp b/Source/core/workers/WorkerThread.cpp
index 343163a4a45b5f4ee038d6b5df20fa1441188168..6c163b391b07dcb30bc14cd5ca9b497d6ade0d47 100644
--- a/Source/core/workers/WorkerThread.cpp
+++ b/Source/core/workers/WorkerThread.cpp
@@ -29,6 +29,7 @@
#include "core/workers/WorkerThread.h"
#include "bindings/core/v8/ScriptSourceCode.h"
+#include "core/dom/Microtask.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/WorkerInspectorController.h"
#include "core/workers/DedicatedWorkerGlobalScope.h"
@@ -54,7 +55,17 @@ namespace blink {
namespace {
const int64 kShortIdleHandlerDelayMs = 1000;
const int64 kLongIdleHandlerDelayMs = 10*1000;
-}
+
+class MicrotaskRunner : public WebThread::TaskObserver {
+public:
+ virtual void willProcessTask() OVERRIDE { }
+ virtual void didProcessTask() OVERRIDE
+ {
+ Microtask::performCheckpoint();
+ }
+};
+
+} // namespace
static Mutex& threadSetMutex()
{
@@ -229,6 +240,8 @@ void WorkerThread::initialize()
KURL scriptURL = m_startupData->m_scriptURL;
String sourceCode = m_startupData->m_sourceCode;
WorkerThreadStartMode startMode = m_startupData->m_startMode;
+ m_microtaskRunner = adoptPtr(new MicrotaskRunner);
+ m_thread->addTaskObserver(m_microtaskRunner.get());
{
MutexLocker lock(m_threadCreationMutex);
@@ -295,6 +308,8 @@ void WorkerThread::cleanup()
// the heap for this thread will need to access thread local data.
ThreadState::detach();
+ m_thread->removeTaskObserver(m_microtaskRunner.get());
+ m_microtaskRunner = nullptr;
m_thread->removeTaskObserver(m_pendingGCRunner.get());
m_pendingGCRunner = nullptr;
m_messageLoopInterruptor = nullptr;
« no previous file with comments | « Source/core/workers/WorkerThread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698