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

Unified Diff: third_party/WebKit/WebCore/dom/WorkerRunLoop.cpp

Issue 20076: WebKit merge 40500:40539 [WebKit side] (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | « third_party/WebKit/WebCore/dom/WorkerRunLoop.h ('k') | third_party/WebKit/WebCore/dom/WorkerTask.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/WebCore/dom/WorkerRunLoop.cpp
===================================================================
--- third_party/WebKit/WebCore/dom/WorkerRunLoop.cpp (revision 9118)
+++ third_party/WebKit/WebCore/dom/WorkerRunLoop.cpp (working copy)
@@ -32,26 +32,75 @@
#if ENABLE(WORKERS)
+#include "ScriptExecutionContext.h"
+#include "ThreadGlobalData.h"
+#include "ThreadTimers.h"
#include "WorkerRunLoop.h"
#include "WorkerContext.h"
-#include "WorkerTask.h"
#include "WorkerThread.h"
namespace WebCore {
+class WorkerSharedTimer : public SharedTimer {
+public:
+ WorkerSharedTimer()
+ : m_sharedTimerFunction(0)
+ , m_nextFireTime(0)
+ {
+ }
+
+ // SharedTimer interface.
+ virtual void setFiredFunction(void (*function)()) { m_sharedTimerFunction = function; }
+ virtual void setFireTime(double fireTime) { m_nextFireTime = fireTime; }
+ virtual void stop() { m_nextFireTime = 0; }
+
+ bool isActive() { return m_sharedTimerFunction && m_nextFireTime; }
+ double fireTime() { return m_nextFireTime; }
+ void fire() { m_sharedTimerFunction(); }
+
+private:
+ void (*m_sharedTimerFunction)();
+ double m_nextFireTime;
+};
+
+WorkerRunLoop::WorkerRunLoop()
+ : m_sharedTimer(new WorkerSharedTimer)
+{
+}
+
+WorkerRunLoop::~WorkerRunLoop()
+{
+}
+
void WorkerRunLoop::run(WorkerContext* context)
{
ASSERT(context);
ASSERT(context->thread());
ASSERT(context->thread()->threadID() == currentThread());
-
+
+ threadGlobalData().threadTimers().setSharedTimer(m_sharedTimer.get());
+
while (true) {
- RefPtr<WorkerTask> task;
- if (!m_messageQueue.waitForMessage(task))
+ RefPtr<ScriptExecutionContext::Task> task;
+ MessageQueueWaitResult result;
+
+ if (m_sharedTimer->isActive())
+ result = m_messageQueue.waitForMessageTimed(task, m_sharedTimer->fireTime());
+ else
+ result = (m_messageQueue.waitForMessage(task) ? MessageQueueMessageReceived : MessageQueueTerminated);
+
+ if (result == MessageQueueTerminated)
break;
+
+ if (result == MessageQueueMessageReceived)
+ task->performTask(context);
+ else {
+ ASSERT(result == MessageQueueTimeout);
+ m_sharedTimer->fire();
+ }
+ }
- task->performTask(context);
- }
+ threadGlobalData().threadTimers().setSharedTimer(0);
}
void WorkerRunLoop::terminate()
@@ -59,7 +108,7 @@
m_messageQueue.kill();
}
-void WorkerRunLoop::postTask(PassRefPtr<WorkerTask> task)
+void WorkerRunLoop::postTask(PassRefPtr<ScriptExecutionContext::Task> task)
{
m_messageQueue.append(task);
}
« no previous file with comments | « third_party/WebKit/WebCore/dom/WorkerRunLoop.h ('k') | third_party/WebKit/WebCore/dom/WorkerTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698