<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[215223] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/215223">215223</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2017-04-11 02:34:36 -0700 (Tue, 11 Apr 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Enable JSRunLoopTimer for JSCOnly and Windows
https://bugs.webkit.org/show_bug.cgi?id=170655

Reviewed by Carlos Garcia Campos.

Source/JavaScriptCore:

* runtime/JSRunLoopTimer.cpp:
(JSC::JSRunLoopTimer::JSRunLoopTimer):
(JSC::JSRunLoopTimer::scheduleTimer):
(JSC::JSRunLoopTimer::cancelTimer):
* runtime/JSRunLoopTimer.h:

Source/WTF:

This patch makes RunLoop::Timer in Generic and Windows thread-safe to use it
in JSC's JSRunLoopTimer. Eventually, we would like to replace JSRunLoopTimer's
platform-dependent implementation to WTF::RunLoop::Timer.

* wtf/RunLoop.h:
* wtf/cf/RunLoopCF.cpp:
(WTF::RunLoop::TimerBase::start):
* wtf/generic/RunLoopGeneric.cpp:
(WTF::RunLoop::TimerBase::ScheduledTask::EarliestSchedule::operator()):
(WTF::RunLoop::populateTasks):
(WTF::RunLoop::runImpl):
(WTF::RunLoop::schedule):
(WTF::RunLoop::scheduleAndWakeUp):
(WTF::RunLoop::TimerBase::~TimerBase):
(WTF::RunLoop::TimerBase::start):
(WTF::RunLoop::TimerBase::stop):
(WTF::RunLoop::TimerBase::isActive):
* wtf/glib/RunLoopGLib.cpp:
(WTF::RunLoop::TimerBase::TimerBase):
* wtf/win/RunLoopWin.cpp:
(WTF::RunLoop::TimerBase::timerFired):
(WTF::RunLoop::TimerBase::start):
(WTF::RunLoop::TimerBase::stop):
(WTF::RunLoop::TimerBase::isActive):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSRunLoopTimercpp">trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSRunLoopTimerh">trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfRunLooph">trunk/Source/WTF/wtf/RunLoop.h</a></li>
<li><a href="#trunkSourceWTFwtfcfRunLoopCFcpp">trunk/Source/WTF/wtf/cf/RunLoopCF.cpp</a></li>
<li><a href="#trunkSourceWTFwtfgenericRunLoopGenericcpp">trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp</a></li>
<li><a href="#trunkSourceWTFwtfglibRunLoopGLibcpp">trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp</a></li>
<li><a href="#trunkSourceWTFwtfwinRunLoopWincpp">trunk/Source/WTF/wtf/win/RunLoopWin.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2017-04-11  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
+        [JSC] Enable JSRunLoopTimer for JSCOnly and Windows
+        https://bugs.webkit.org/show_bug.cgi?id=170655
+
+        Reviewed by Carlos Garcia Campos.
+
+        * runtime/JSRunLoopTimer.cpp:
+        (JSC::JSRunLoopTimer::JSRunLoopTimer):
+        (JSC::JSRunLoopTimer::scheduleTimer):
+        (JSC::JSRunLoopTimer::cancelTimer):
+        * runtime/JSRunLoopTimer.h:
+
</ins><span class="cx"> 2017-04-10  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Revert r215217
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSRunLoopTimercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -161,10 +161,17 @@
</span><span class="cx">     g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + s_decade * G_USEC_PER_SEC);
</span><span class="cx">     m_isScheduled = false;
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> #else
</span><ins>+
+const Seconds JSRunLoopTimer::s_decade { 60 * 60 * 24 * 365 * 10 };
+
</ins><span class="cx"> JSRunLoopTimer::JSRunLoopTimer(VM* vm)
</span><span class="cx">     : m_vm(vm)
</span><ins>+    , m_apiLock(&amp;vm-&gt;apiLock())
+    , m_timer(RunLoop::current(), this, &amp;JSRunLoopTimer::timerDidFire)
</ins><span class="cx"> {
</span><ins>+    m_timer.startOneShot(s_decade);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> JSRunLoopTimer::~JSRunLoopTimer()
</span><span class="lines">@@ -171,13 +178,18 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSRunLoopTimer::scheduleTimer(double)
</del><ins>+void JSRunLoopTimer::scheduleTimer(double intervalInSeconds)
</ins><span class="cx"> {
</span><ins>+    m_timer.startOneShot(intervalInSeconds);
+    m_isScheduled = true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void JSRunLoopTimer::cancelTimer()
</span><span class="cx"> {
</span><ins>+    m_timer.startOneShot(s_decade);
+    m_isScheduled = false;
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> #endif
</span><del>-    
</del><ins>+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSRunLoopTimerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include &lt;wtf/Lock.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><ins>+#include &lt;wtf/RunLoop.h&gt;
</ins><span class="cx"> #include &lt;wtf/ThreadSafeRefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -79,6 +80,9 @@
</span><span class="cx"> #elif USE(GLIB)
</span><span class="cx">     static const long s_decade;
</span><span class="cx">     GRefPtr&lt;GSource&gt; m_timer;
</span><ins>+#else
+    static const Seconds s_decade;
+    RunLoop::Timer&lt;JSRunLoopTimer&gt; m_timer;
</ins><span class="cx"> #endif
</span><span class="cx">     
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/WTF/ChangeLog        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2017-04-11  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
+        [JSC] Enable JSRunLoopTimer for JSCOnly and Windows
+        https://bugs.webkit.org/show_bug.cgi?id=170655
+
+        Reviewed by Carlos Garcia Campos.
+
+        This patch makes RunLoop::Timer in Generic and Windows thread-safe to use it
+        in JSC's JSRunLoopTimer. Eventually, we would like to replace JSRunLoopTimer's
+        platform-dependent implementation to WTF::RunLoop::Timer.
+
+        * wtf/RunLoop.h:
+        * wtf/cf/RunLoopCF.cpp:
+        (WTF::RunLoop::TimerBase::start):
+        * wtf/generic/RunLoopGeneric.cpp:
+        (WTF::RunLoop::TimerBase::ScheduledTask::EarliestSchedule::operator()):
+        (WTF::RunLoop::populateTasks):
+        (WTF::RunLoop::runImpl):
+        (WTF::RunLoop::schedule):
+        (WTF::RunLoop::scheduleAndWakeUp):
+        (WTF::RunLoop::TimerBase::~TimerBase):
+        (WTF::RunLoop::TimerBase::start):
+        (WTF::RunLoop::TimerBase::stop):
+        (WTF::RunLoop::TimerBase::isActive):
+        * wtf/glib/RunLoopGLib.cpp:
+        (WTF::RunLoop::TimerBase::TimerBase):
+        * wtf/win/RunLoopWin.cpp:
+        (WTF::RunLoop::TimerBase::timerFired):
+        (WTF::RunLoop::TimerBase::start):
+        (WTF::RunLoop::TimerBase::stop):
+        (WTF::RunLoop::TimerBase::isActive):
+
</ins><span class="cx"> 2017-04-11  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r213645): It made JSC tests super slow and timeout on AArch64 Linux
</span></span></pre></div>
<a id="trunkSourceWTFwtfRunLooph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/RunLoop.h (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RunLoop.h        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/WTF/wtf/RunLoop.h        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -103,7 +103,7 @@
</span><span class="cx">     private:
</span><span class="cx">         WTF_EXPORT_PRIVATE void start(double nextFireInterval, bool repeat);
</span><span class="cx"> 
</span><del>-        RunLoop&amp; m_runLoop;
</del><ins>+        Ref&lt;RunLoop&gt; m_runLoop;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(WINDOWS_EVENT_LOOP)
</span><span class="cx">         static void timerFired(RunLoop*, uint64_t ID);
</span><span class="lines">@@ -118,6 +118,9 @@
</span><span class="cx">         bool m_isRepeating { false };
</span><span class="cx">         Seconds m_fireInterval { 0 };
</span><span class="cx"> #elif USE(GENERIC_EVENT_LOOP)
</span><ins>+        bool isActive(const AbstractLocker&amp;) const;
+        void stop(const AbstractLocker&amp;);
+
</ins><span class="cx">         class ScheduledTask;
</span><span class="cx">         RefPtr&lt;ScheduledTask&gt; m_scheduledTask;
</span><span class="cx"> #endif
</span><span class="lines">@@ -159,6 +162,7 @@
</span><span class="cx">     HWND m_runLoopMessageWindow;
</span><span class="cx"> 
</span><span class="cx">     typedef HashMap&lt;uint64_t, TimerBase*&gt; TimerMap;
</span><ins>+    Lock m_activeTimersLock;
</ins><span class="cx">     TimerMap m_activeTimers;
</span><span class="cx"> #elif USE(COCOA_EVENT_LOOP)
</span><span class="cx">     static void performWork(void*);
</span><span class="lines">@@ -172,7 +176,7 @@
</span><span class="cx">     void schedule(Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp;);
</span><span class="cx">     void schedule(const AbstractLocker&amp;, Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp;);
</span><span class="cx">     void wakeUp(const AbstractLocker&amp;);
</span><del>-    void scheduleAndWakeUp(Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp;);
</del><ins>+    void scheduleAndWakeUp(const AbstractLocker&amp;, Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp;);
</ins><span class="cx"> 
</span><span class="cx">     enum class RunMode {
</span><span class="cx">         Iterate,
</span><span class="lines">@@ -184,12 +188,14 @@
</span><span class="cx">         Stopping,
</span><span class="cx">     };
</span><span class="cx">     void runImpl(RunMode);
</span><del>-    bool populateTasks(RunMode, Status&amp;, Deque&lt;Ref&lt;TimerBase::ScheduledTask&gt;&gt;&amp;);
</del><ins>+    bool populateTasks(RunMode, Status&amp;, Deque&lt;RefPtr&lt;TimerBase::ScheduledTask&gt;&gt;&amp;);
</ins><span class="cx"> 
</span><ins>+    friend class TimerBase;
+
</ins><span class="cx">     Lock m_loopLock;
</span><span class="cx">     Condition m_readyToRun;
</span><span class="cx">     Condition m_stopCondition;
</span><del>-    Vector&lt;Ref&lt;TimerBase::ScheduledTask&gt;&gt; m_schedules;
</del><ins>+    Vector&lt;RefPtr&lt;TimerBase::ScheduledTask&gt;&gt; m_schedules;
</ins><span class="cx">     Vector&lt;Status*&gt; m_mainLoops;
</span><span class="cx">     bool m_shutdown { false };
</span><span class="cx">     bool m_pendingTasks { false };
</span></span></pre></div>
<a id="trunkSourceWTFwtfcfRunLoopCFcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/cf/RunLoopCF.cpp (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/cf/RunLoopCF.cpp        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/WTF/wtf/cf/RunLoopCF.cpp        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -102,7 +102,7 @@
</span><span class="cx">     CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
</span><span class="cx">     CFTimeInterval repeatInterval = repeat ? nextFireInterval : 0;
</span><span class="cx">     m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &amp;context));
</span><del>-    CFRunLoopAddTimer(m_runLoop.m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
</del><ins>+    CFRunLoopAddTimer(m_runLoop-&gt;m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RunLoop::TimerBase::stop()
</span></span></pre></div>
<a id="trunkSourceWTFwtfgenericRunLoopGenericcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     struct EarliestSchedule {
</span><del>-        bool operator()(const Ref&lt;ScheduledTask&gt;&amp; lhs, const Ref&lt;ScheduledTask&gt;&amp; rhs)
</del><ins>+        bool operator()(const RefPtr&lt;ScheduledTask&gt;&amp; lhs, const RefPtr&lt;ScheduledTask&gt;&amp; rhs)
</ins><span class="cx">         {
</span><span class="cx">             return lhs-&gt;scheduledTimePoint() &gt; rhs-&gt;scheduledTimePoint();
</span><span class="cx">         }
</span><span class="lines">@@ -112,7 +112,7 @@
</span><span class="cx">         m_stopCondition.wait(m_loopLock);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline bool RunLoop::populateTasks(RunMode runMode, Status&amp; statusOfThisLoop, Deque&lt;Ref&lt;TimerBase::ScheduledTask&gt;&gt;&amp; firedTimers)
</del><ins>+inline bool RunLoop::populateTasks(RunMode runMode, Status&amp; statusOfThisLoop, Deque&lt;RefPtr&lt;TimerBase::ScheduledTask&gt;&gt;&amp; firedTimers)
</ins><span class="cx"> {
</span><span class="cx">     LockHolder locker(m_loopLock);
</span><span class="cx"> 
</span><span class="lines">@@ -139,7 +139,7 @@
</span><span class="cx">     // Check expired timers.
</span><span class="cx">     MonotonicTime now = MonotonicTime::now();
</span><span class="cx">     while (!m_schedules.isEmpty()) {
</span><del>-        Ref&lt;TimerBase::ScheduledTask&gt; earliest = m_schedules.first().copyRef();
</del><ins>+        RefPtr&lt;TimerBase::ScheduledTask&gt; earliest = m_schedules.first();
</ins><span class="cx">         if (earliest-&gt;scheduledTimePoint() &gt; now)
</span><span class="cx">             break;
</span><span class="cx">         std::pop_heap(m_schedules.begin(), m_schedules.end(), TimerBase::ScheduledTask::EarliestSchedule());
</span><span class="lines">@@ -160,7 +160,7 @@
</span><span class="cx">         m_mainLoops.append(&amp;statusOfThisLoop);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Deque&lt;Ref&lt;TimerBase::ScheduledTask&gt;&gt; firedTimers;
</del><ins>+    Deque&lt;RefPtr&lt;TimerBase::ScheduledTask&gt;&gt; firedTimers;
</ins><span class="cx">     while (true) {
</span><span class="cx">         if (!populateTasks(runMode, statusOfThisLoop, firedTimers))
</span><span class="cx">             return;
</span><span class="lines">@@ -167,12 +167,12 @@
</span><span class="cx"> 
</span><span class="cx">         // Dispatch scheduled timers.
</span><span class="cx">         while (!firedTimers.isEmpty()) {
</span><del>-            Ref&lt;TimerBase::ScheduledTask&gt; task = firedTimers.takeFirst();
</del><ins>+            RefPtr&lt;TimerBase::ScheduledTask&gt; task = firedTimers.takeFirst();
</ins><span class="cx">             if (task-&gt;fired()) {
</span><span class="cx">                 // Reschedule because the timer requires repeating.
</span><span class="cx">                 // Since we will query the timers' time points before sleeping,
</span><span class="cx">                 // we do not call wakeUp() here.
</span><del>-                schedule(WTFMove(task));
</del><ins>+                schedule(*task);
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">         performWork();
</span><span class="lines">@@ -220,7 +220,7 @@
</span><span class="cx"> 
</span><span class="cx"> void RunLoop::schedule(const AbstractLocker&amp;, Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp; task)
</span><span class="cx"> {
</span><del>-    m_schedules.append(WTFMove(task));
</del><ins>+    m_schedules.append(task.ptr());
</ins><span class="cx">     std::push_heap(m_schedules.begin(), m_schedules.end(), TimerBase::ScheduledTask::EarliestSchedule());
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -230,9 +230,8 @@
</span><span class="cx">     schedule(locker, WTFMove(task));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RunLoop::scheduleAndWakeUp(Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp; task)
</del><ins>+void RunLoop::scheduleAndWakeUp(const AbstractLocker&amp; locker, Ref&lt;TimerBase::ScheduledTask&gt;&amp;&amp; task)
</ins><span class="cx"> {
</span><del>-    LockHolder locker(m_loopLock);
</del><span class="cx">     schedule(locker, WTFMove(task));
</span><span class="cx">     wakeUp(locker);
</span><span class="cx"> }
</span><span class="lines">@@ -247,11 +246,6 @@
</span><span class="cx"> 
</span><span class="cx"> // Since RunLoop does not own the registered TimerBase,
</span><span class="cx"> // TimerBase and its owner should manage these lifetime.
</span><del>-//
-// And more importantly, TimerBase operations are not thread-safe.
-// So threads that do not belong to the ScheduledTask's RunLoop
-// should not operate the RunLoop::TimerBase.
-// This is the same to the RunLoopWin, which is RunLoop for Windows.
</del><span class="cx"> RunLoop::TimerBase::TimerBase(RunLoop&amp; runLoop)
</span><span class="cx">     : m_runLoop(runLoop)
</span><span class="cx">     , m_scheduledTask(nullptr)
</span><span class="lines">@@ -260,19 +254,21 @@
</span><span class="cx"> 
</span><span class="cx"> RunLoop::TimerBase::~TimerBase()
</span><span class="cx"> {
</span><del>-    stop();
</del><ins>+    LockHolder locker(m_runLoop-&gt;m_loopLock);
+    stop(locker);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RunLoop::TimerBase::start(double interval, bool repeating)
</span><span class="cx"> {
</span><del>-    stop();
</del><ins>+    LockHolder locker(m_runLoop-&gt;m_loopLock);
+    stop(locker);
</ins><span class="cx">     m_scheduledTask = ScheduledTask::create([this] {
</span><span class="cx">         fired();
</span><span class="cx">     }, Seconds(interval), repeating);
</span><del>-    m_runLoop.scheduleAndWakeUp(*m_scheduledTask);
</del><ins>+    m_runLoop-&gt;scheduleAndWakeUp(locker, *m_scheduledTask);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RunLoop::TimerBase::stop()
</del><ins>+void RunLoop::TimerBase::stop(const AbstractLocker&amp;)
</ins><span class="cx"> {
</span><span class="cx">     if (m_scheduledTask) {
</span><span class="cx">         m_scheduledTask-&gt;deactivate();
</span><span class="lines">@@ -280,8 +276,20 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RunLoop::TimerBase::stop()
+{
+    LockHolder locker(m_runLoop-&gt;m_loopLock);
+    stop(locker);
+}
+
</ins><span class="cx"> bool RunLoop::TimerBase::isActive() const
</span><span class="cx"> {
</span><ins>+    LockHolder locker(m_runLoop-&gt;m_loopLock);
+    return isActive(locker);
+}
+
+bool RunLoop::TimerBase::isActive(const AbstractLocker&amp;) const
+{
</ins><span class="cx">     return m_scheduledTask;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFwtfglibRunLoopGLibcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -168,7 +168,7 @@
</span><span class="cx">             timer-&gt;updateReadyTime();
</span><span class="cx">         return G_SOURCE_CONTINUE;
</span><span class="cx">     }, this, nullptr);
</span><del>-    g_source_attach(m_source.get(), m_runLoop.m_mainContext.get());
</del><ins>+    g_source_attach(m_source.get(), m_runLoop-&gt;m_mainContext.get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> RunLoop::TimerBase::~TimerBase()
</span></span></pre></div>
<a id="trunkSourceWTFwtfwinRunLoopWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/win/RunLoopWin.cpp (215222 => 215223)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/win/RunLoopWin.cpp        2017-04-11 09:20:16 UTC (rev 215222)
+++ trunk/Source/WTF/wtf/win/RunLoopWin.cpp        2017-04-11 09:34:36 UTC (rev 215223)
</span><span class="lines">@@ -117,17 +117,21 @@
</span><span class="cx"> 
</span><span class="cx"> void RunLoop::TimerBase::timerFired(RunLoop* runLoop, uint64_t ID)
</span><span class="cx"> {
</span><del>-    TimerMap::iterator it = runLoop-&gt;m_activeTimers.find(ID);
-    if (it == runLoop-&gt;m_activeTimers.end()) {
-        // The timer must have been stopped after the WM_TIMER message was posted to the message queue.
-        return;
-    }
</del><ins>+    TimerBase* timer = nullptr;
+    {
+        LockHolder locker(runLoop-&gt;m_activeTimersLock);
+        TimerMap::iterator it = runLoop-&gt;m_activeTimers.find(ID);
+        if (it == runLoop-&gt;m_activeTimers.end()) {
+            // The timer must have been stopped after the WM_TIMER message was posted to the message queue.
+            return;
+        }
</ins><span class="cx"> 
</span><del>-    TimerBase* timer = it-&gt;value;
</del><ins>+        timer = it-&gt;value;
</ins><span class="cx"> 
</span><del>-    if (!timer-&gt;m_isRepeating) {
-        runLoop-&gt;m_activeTimers.remove(it);
-        ::KillTimer(runLoop-&gt;m_runLoopMessageWindow, ID);
</del><ins>+        if (!timer-&gt;m_isRepeating) {
+            runLoop-&gt;m_activeTimers.remove(it);
+            ::KillTimer(runLoop-&gt;m_runLoopMessageWindow, ID);
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     timer-&gt;fired();
</span><span class="lines">@@ -153,24 +157,27 @@
</span><span class="cx"> 
</span><span class="cx"> void RunLoop::TimerBase::start(double nextFireInterval, bool repeat)
</span><span class="cx"> {
</span><ins>+    LockHolder locker(m_runLoop-&gt;m_activeTimersLock);
</ins><span class="cx">     m_isRepeating = repeat;
</span><del>-    m_runLoop.m_activeTimers.set(m_ID, this);
-    ::SetTimer(m_runLoop.m_runLoopMessageWindow, m_ID, nextFireInterval * 1000, 0);
</del><ins>+    m_runLoop-&gt;m_activeTimers.set(m_ID, this);
+    ::SetTimer(m_runLoop-&gt;m_runLoopMessageWindow, m_ID, nextFireInterval * 1000, 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RunLoop::TimerBase::stop()
</span><span class="cx"> {
</span><del>-    TimerMap::iterator it = m_runLoop.m_activeTimers.find(m_ID);
-    if (it == m_runLoop.m_activeTimers.end())
</del><ins>+    LockHolder locker(m_runLoop-&gt;m_activeTimersLock);
+    TimerMap::iterator it = m_runLoop-&gt;m_activeTimers.find(m_ID);
+    if (it == m_runLoop-&gt;m_activeTimers.end())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_runLoop.m_activeTimers.remove(it);
-    ::KillTimer(m_runLoop.m_runLoopMessageWindow, m_ID);
</del><ins>+    m_runLoop-&gt;m_activeTimers.remove(it);
+    ::KillTimer(m_runLoop-&gt;m_runLoopMessageWindow, m_ID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RunLoop::TimerBase::isActive() const
</span><span class="cx"> {
</span><del>-    return m_runLoop.m_activeTimers.contains(m_ID);
</del><ins>+    LockHolder locker(m_runLoop-&gt;m_activeTimersLock);
+    return m_runLoop-&gt;m_activeTimers.contains(m_ID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span></span></pre>
</div>
</div>

</body>
</html>