Chromium Code Reviews| Index: Source/core/workers/WorkerThread.cpp |
| diff --git a/Source/core/workers/WorkerThread.cpp b/Source/core/workers/WorkerThread.cpp |
| index 657ab336614bda55f2398b61fc25b02510d19dd9..44bc0ac63feb0ec7d99d50593386545e7a8cf577 100644 |
| --- a/Source/core/workers/WorkerThread.cpp |
| +++ b/Source/core/workers/WorkerThread.cpp |
| @@ -38,9 +38,7 @@ |
| #include "core/workers/WorkerClients.h" |
| #include "core/workers/WorkerReportingProxy.h" |
| #include "core/workers/WorkerThreadStartupData.h" |
| -#include "platform/PlatformThreadData.h" |
| #include "platform/Task.h" |
| -#include "platform/ThreadTimers.h" |
| #include "platform/heap/SafePoint.h" |
| #include "platform/heap/ThreadState.h" |
| #include "platform/weborigin/KURL.h" |
| @@ -54,8 +52,6 @@ |
| namespace blink { |
| namespace { |
| -const int64_t kShortIdleHandlerDelayMs = 1000; |
| -const int64_t kLongIdleHandlerDelayMs = 10*1000; |
| class MicrotaskRunner : public WebThread::TaskObserver { |
| public: |
| @@ -131,69 +127,6 @@ private: |
| bool m_taskCanceled; |
| }; |
| -class WorkerSharedTimer : public SharedTimer { |
| -public: |
| - explicit WorkerSharedTimer(WorkerThread* workerThread) |
| - : m_workerThread(workerThread) |
| - , m_running(false) |
| - { } |
| - |
| - typedef void (*SharedTimerFunction)(); |
| - virtual void setFiredFunction(SharedTimerFunction func) |
| - { |
| - m_sharedTimerFunction = func; |
| - } |
| - |
| - virtual void setFireInterval(double interval) |
| - { |
| - ASSERT(m_sharedTimerFunction); |
| - |
| - // See BlinkPlatformImpl::setSharedTimerFireInterval for explanation of |
| - // why ceil is used in the interval calculation. |
| - int64_t delay = static_cast<int64_t>(ceil(interval * 1000)); |
| - |
| - if (delay < 0) { |
| - delay = 0; |
| - } |
| - |
| - m_running = true; |
| - |
| - if (m_lastQueuedTask.get()) |
| - m_lastQueuedTask->cancelTask(); |
| - |
| - // Now queue the task as a cancellable one. |
| - OwnPtr<WorkerThreadCancelableTask> task = WorkerThreadCancelableTask::create(bind(&WorkerSharedTimer::OnTimeout, this)); |
| - m_lastQueuedTask = task->createWeakPtr(); |
| - m_workerThread->postDelayedTask(FROM_HERE, task.release(), delay); |
| - } |
| - |
| - virtual void stop() |
| - { |
| - m_running = false; |
| - m_lastQueuedTask = nullptr; |
| - } |
| - |
| -private: |
| - void OnTimeout() |
| - { |
| - ASSERT(m_workerThread->workerGlobalScope()); |
| - |
| - m_lastQueuedTask = nullptr; |
| - |
| - if (m_sharedTimerFunction && m_running && !m_workerThread->workerGlobalScope()->isClosing()) |
| - m_sharedTimerFunction(); |
| - } |
| - |
| - WorkerThread* m_workerThread; |
| - SharedTimerFunction m_sharedTimerFunction; |
| - bool m_running; |
| - |
| - // The task to run OnTimeout, if any. While OnTimeout resets |
| - // m_lastQueuedTask, this must be a weak pointer because the |
| - // worker runloop may delete the task as it is shutting down. |
| - WeakPtr<WorkerThreadCancelableTask> m_lastQueuedTask; |
| -}; |
| - |
| class WorkerThreadTask : public blink::WebThread::Task { |
| WTF_MAKE_NONCOPYABLE(WorkerThreadTask); WTF_MAKE_FAST_ALLOCATED(WorkerThreadTask); |
| public: |
| @@ -298,6 +231,22 @@ PlatformThreadId WorkerThread::platformThreadId() const |
| return m_thread->platformThread().threadId(); |
| } |
| +class WorkerThreadIdleTask : public WebThread::IdleTask { |
| +public: |
| + explicit WorkerThreadIdleTask(WorkerThread* thread) |
| + : m_thread(thread) { } |
| + |
| + ~WorkerThreadIdleTask() override { } |
| + |
| + void run(double deadlineSeconds) override |
| + { |
| + m_thread->idleTask(deadlineSeconds); |
| + } |
| + |
| +private: |
| + RawPtr<WorkerThread> m_thread; |
| +}; |
| + |
| void WorkerThread::initialize() |
| { |
| KURL scriptURL = m_startupData->m_scriptURL; |
| @@ -324,8 +273,6 @@ void WorkerThread::initialize() |
| m_isolate = initializeIsolate(); |
| m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
| m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.get() ? cachedMetaData->size() : 0); |
| - |
| - PlatformThreadData::current().threadTimers().setSharedTimer(adoptPtr(new WorkerSharedTimer(this))); |
| } |
| // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). |
| @@ -347,7 +294,7 @@ void WorkerThread::initialize() |
| postInitialize(); |
| - postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler, this), kShortIdleHandlerDelayMs); |
| + m_thread->postIdleTaskAfterWakeup(FROM_HERE, new WorkerThreadIdleTask(this)); |
| } |
| PassOwnPtr<WebThreadSupportingGC> WorkerThread::createWebThreadSupportingGC() |
| @@ -380,9 +327,6 @@ void WorkerThread::cleanup() |
| workerReportingProxy().workerThreadTerminated(); |
| m_terminationEvent->signal(); |
| - |
| - // Clean up PlatformThreadData before WTF::WTFThreadData goes away! |
| - PlatformThreadData::current().destroy(); |
| } |
| class WorkerThreadShutdownFinishTask : public ExecutionContextTask { |
| @@ -417,7 +361,6 @@ public: |
| { |
| WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); |
| workerGlobalScope->stopActiveDOMObjects(); |
| - PlatformThreadData::current().threadTimers().setSharedTimer(nullptr); |
| // Event listeners would keep DOMWrapperWorld objects alive for too long. Also, they have references to JS objects, |
| // which become dangling once Heap is destroyed. |
| @@ -509,21 +452,20 @@ bool WorkerThread::isCurrentThread() const |
| return m_thread && m_thread->isCurrentThread(); |
| } |
| -void WorkerThread::idleHandler() |
| +void WorkerThread::idleTask(double deadlineSeconds) |
| { |
| - ASSERT(m_workerGlobalScope.get()); |
| - int64_t delay = kLongIdleHandlerDelayMs; |
|
rmcilroy
2015/04/13 13:55:07
I've just realized that this was previously sendin
alex clarke (OOO till 29th)
2015/04/14 13:04:35
OK I can do that, but I need to wire CanExceedIdle
|
| + if (doIdleGc(deadlineSeconds)) |
| + m_thread->postIdleTaskAfterWakeup(FROM_HERE, new WorkerThreadIdleTask(this)); |
| + else |
| + m_thread->postIdleTask(FROM_HERE, new WorkerThreadIdleTask(this)); |
| +} |
| - // Do a script engine idle notification if the next event is distant enough. |
| - const double kMinIdleTimespan = 0.3; |
| - const double nextFireTime = PlatformThreadData::current().threadTimers().nextFireTime(); |
| - if (nextFireTime == 0.0 || nextFireTime > currentTime() + kMinIdleTimespan) { |
| - bool hasMoreWork = !isolate()->IdleNotificationDeadline(Platform::current()->monotonicallyIncreasingTime() + 1.0); |
| - if (hasMoreWork) |
| - delay = kShortIdleHandlerDelayMs; |
| - } |
| +bool WorkerThread::doIdleGc(double deadlineSeconds) |
| +{ |
| + if (deadlineSeconds > Platform::current()->monotonicallyIncreasingTime()) |
| + return isolate()->IdleNotificationDeadline(deadlineSeconds); |
| - postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler, this), delay); |
| + return false; |
| } |
| void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task) |