[RunLoopGeneric] OneShotTimer should be inactive when fired.
authoryoshiaki.jitsukawa@sony.com <yoshiaki.jitsukawa@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2018 16:27:25 +0000 (16:27 +0000)
committeryoshiaki.jitsukawa@sony.com <yoshiaki.jitsukawa@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2018 16:27:25 +0000 (16:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189335

Reviewed by Yusuke Suzuki.

Source/WTF:

* wtf/generic/RunLoopGeneric.cpp:
(WTF::RunLoop::TimerBase::ScheduledTask::fired):
(WTF::RunLoop::TimerBase::isActive const):

Deactivate one-shot timer before invoking its callback.

Tools:

* TestWebKitAPI/Tests/WTF/RunLoop.cpp:
(TestWebKitAPI::TEST):

Add test expectations about timer's active state.

Add a new test to restart a one-shot timer within
its fired callback.

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

Source/WTF/ChangeLog
Source/WTF/wtf/generic/RunLoopGeneric.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp

index b4983ab..7256148 100644 (file)
@@ -1,3 +1,16 @@
+2018-09-07  Yoshiaki Jitsukawa  <yoshiaki.jitsukawa@sony.com>
+
+        [RunLoopGeneric] OneShotTimer should be inactive when fired.
+        https://bugs.webkit.org/show_bug.cgi?id=189335
+
+        Reviewed by Yusuke Suzuki.
+
+        * wtf/generic/RunLoopGeneric.cpp:
+        (WTF::RunLoop::TimerBase::ScheduledTask::fired):
+        (WTF::RunLoop::TimerBase::isActive const):
+
+        Deactivate one-shot timer before invoking its callback. 
+
 2018-09-05  Brent Fulgham  <bfulgham@apple.com>
 
         The width of an empty or nullptr TextRun should be zero
index 7869199..b45b1b9 100644 (file)
@@ -50,12 +50,13 @@ public:
         if (!isActive())
             return false;
 
-        m_function();
-
         if (!m_isRepeating)
-            return false;
+            deactivate();
 
-        updateReadyTime();
+        m_function();
+
+        if (isActive())
+            updateReadyTime();
         return isActive();
     }
 
@@ -290,7 +291,7 @@ bool RunLoop::TimerBase::isActive() const
 
 bool RunLoop::TimerBase::isActive(const AbstractLocker&) const
 {
-    return m_scheduledTask;
+    return m_scheduledTask && m_scheduledTask->isActive();
 }
 
 Seconds RunLoop::TimerBase::secondsUntilFire() const
index 051a402..187ba92 100644 (file)
@@ -1,3 +1,18 @@
+2018-09-07  Yoshiaki Jitsukawa  <yoshiaki.jitsukawa@sony.com>
+
+        [RunLoopGeneric] OneShotTimer should be inactive when fired.
+        https://bugs.webkit.org/show_bug.cgi?id=189335
+
+        Reviewed by Yusuke Suzuki.
+
+        * TestWebKitAPI/Tests/WTF/RunLoop.cpp:
+        (TestWebKitAPI::TEST):
+
+        Add test expectations about timer's active state.
+
+        Add a new test to restart a one-shot timer within
+        its fired callback.
+
 2018-09-06  Zalan Bujtas  <zalan@apple.com>
 
         [LFC] Add support for min/max-height percentage values.
index 93b3d8c..33c69ff 100644 (file)
@@ -85,6 +85,7 @@ TEST(WTF_RunLoop, OneShotTimer)
 
         void fired()
         {
+            EXPECT_FALSE(isActive());
             m_testFinished = true;
             stop();
         }
@@ -100,6 +101,44 @@ TEST(WTF_RunLoop, OneShotTimer)
     }
 }
 
+TEST(WTF_RunLoop, ChainingOneShotTimer)
+{
+    RunLoop::initializeMainRunLoop();
+
+    bool testFinished = false;
+
+    class DerivedTimer : public RunLoop::Timer<DerivedTimer> {
+    public:
+        DerivedTimer(bool& testFinished)
+            : RunLoop::Timer<DerivedTimer>(RunLoop::current(), this, &DerivedTimer::fired)
+            , m_testFinished(testFinished)
+        {
+        }
+
+        void fired()
+        {
+            EXPECT_FALSE(isActive());
+            if (++m_count != 2) {
+                startOneShot(100_ms);
+                EXPECT_TRUE(isActive());
+            } else {
+                m_testFinished = true;
+                stop();
+            }
+        }
+
+    private:
+        unsigned m_count { 0 };
+        bool& m_testFinished;
+    };
+
+    {
+        DerivedTimer timer(testFinished);
+        timer.startOneShot(100_ms);
+        Util::run(&testFinished);
+    }
+}
+
 TEST(WTF_RunLoop, RepeatingTimer)
 {
     RunLoop::initializeMainRunLoop();
@@ -116,6 +155,7 @@ TEST(WTF_RunLoop, RepeatingTimer)
 
         void fired()
         {
+            EXPECT_TRUE(isActive());
             if (++m_count == 10) {
                 m_testFinished = true;
                 stop();