Remove sleep(double) and sleepMS(double) interfaces
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Feb 2018 18:54:07 +0000 (18:54 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Feb 2018 18:54:07 +0000 (18:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183038

Reviewed by Mark Lam.

Source/JavaScriptCore:

* bytecode/SuperSampler.cpp:
(JSC::initializeSuperSampler):

Source/WebKit:

* PluginProcess/WebProcessConnection.cpp:
(WebKit::WebProcessConnection::createPluginAsynchronously):
* UIProcess/linux/MemoryPressureMonitor.cpp:
(WebKit::pollIntervalForUsedMemoryPercentage):
(WebKit::MemoryPressureMonitor::MemoryPressureMonitor):
* WebProcess/wpe/WebProcessMainWPE.cpp:

Source/WTF:

This patch removes sleep(double) and sleepMS(double) interfaces.
We can just use sleep(Seconds) instead.

* benchmarks/LockFairnessTest.cpp:
* benchmarks/LockSpeedTest.cpp:
* wtf/CurrentTime.cpp:
(WTF::sleep):
* wtf/CurrentTime.h:
(WTF::sleepMS): Deleted.
* wtf/DebugUtilities.h:
* wtf/Seconds.cpp:
(WTF::sleep): Deleted.
* wtf/Seconds.h:
* wtf/StackShotProfiler.h:

Tools:

* DumpRenderTree/TestNetscapePlugIn/PluginTest.cpp:
(PluginTest::indicateTestFailure):
* DumpRenderTree/TestNetscapePlugIn/Tests/EvaluateJSWithinNPP_New.cpp:
(EvaluteJSWithinNPP_New::NPP_New):
* DumpRenderTree/TestNetscapePlugIn/Tests/InvokeDestroysPluginWithinNPP_New.cpp:
(InvokeDestroysPluginWithinNPP_New::NPP_New):
* DumpRenderTree/TestNetscapePlugIn/Tests/SlowNPPNew.cpp:
* TestWebKitAPI/Tests/WTF/Signals.cpp:
(TEST):
* TestWebKitAPI/Tests/WTF/ThreadGroup.cpp:
(TestWebKitAPI::testThreadGroup):
* TestWebKitAPI/Tests/WTF/WorkQueue.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/jsconly/PlatformUtilitiesJSCOnly.cpp:
(TestWebKitAPI::Util::sleep):

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

26 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/SuperSampler.cpp
Source/WTF/ChangeLog
Source/WTF/benchmarks/LockFairnessTest.cpp
Source/WTF/benchmarks/LockSpeedTest.cpp
Source/WTF/wtf/CurrentTime.cpp
Source/WTF/wtf/CurrentTime.h
Source/WTF/wtf/DebugUtilities.h
Source/WTF/wtf/Seconds.cpp
Source/WTF/wtf/Seconds.h
Source/WTF/wtf/StackShotProfiler.h
Source/WebKit/ChangeLog
Source/WebKit/PluginProcess/WebProcessConnection.cpp
Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp
Source/WebKit/WebProcess/wpe/WebProcessMainWPE.cpp
Tools/ChangeLog
Tools/DumpRenderTree/TestNetscapePlugIn/PluginTest.cpp
Tools/DumpRenderTree/TestNetscapePlugIn/Tests/EvaluateJSWithinNPP_New.cpp
Tools/DumpRenderTree/TestNetscapePlugIn/Tests/InvokeDestroysPluginWithinNPP_New.cpp
Tools/DumpRenderTree/TestNetscapePlugIn/Tests/SlowNPPNew.cpp
Tools/TestWebKitAPI/Tests/WTF/Signals.cpp
Tools/TestWebKitAPI/Tests/WTF/ThreadGroup.cpp
Tools/TestWebKitAPI/Tests/WTF/WorkQueue.cpp
Tools/TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
Tools/TestWebKitAPI/jsconly/PlatformUtilitiesJSCOnly.cpp

index fe63550..2a9c096 100644 (file)
@@ -1,3 +1,13 @@
+2018-02-22  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Remove sleep(double) and sleepMS(double) interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=183038
+
+        Reviewed by Mark Lam.
+
+        * bytecode/SuperSampler.cpp:
+        (JSC::initializeSuperSampler):
+
 2018-02-21  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake] Split declaration of JSC headers into public and private
index e9b1f5c..7bbac47 100644 (file)
@@ -60,7 +60,7 @@ void initializeSuperSampler()
                         else
                             out++;
                     }
-                    sleepMS(sleepQuantum);
+                    sleep(Seconds::fromMilliseconds(sleepQuantum));
                 }
                 printSuperSamplerState();
                 if (static_cast<int32_t>(g_superSamplerCount) < 0)
index ebb4bc2..4d49db4 100644 (file)
@@ -1,3 +1,25 @@
+2018-02-22  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Remove sleep(double) and sleepMS(double) interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=183038
+
+        Reviewed by Mark Lam.
+
+        This patch removes sleep(double) and sleepMS(double) interfaces.
+        We can just use sleep(Seconds) instead.
+
+        * benchmarks/LockFairnessTest.cpp:
+        * benchmarks/LockSpeedTest.cpp:
+        * wtf/CurrentTime.cpp:
+        (WTF::sleep):
+        * wtf/CurrentTime.h:
+        (WTF::sleepMS): Deleted.
+        * wtf/DebugUtilities.h:
+        * wtf/Seconds.cpp:
+        (WTF::sleep): Deleted.
+        * wtf/Seconds.h:
+        * wtf/StackShotProfiler.h:
+
 2018-02-21  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake][Win] Use cmakeconfig.h rather than config.h and Platform.h
index 0c34653..d7fceda 100644 (file)
@@ -92,10 +92,10 @@ struct Benchmark {
                 });
         }
     
-        sleepMS(100);
+        sleep(100_ms);
         lock.unlock();
     
-        sleep(secondsPerTest);
+        sleep(Seconds { secondsPerTest });
     
         keepGoing = false;
         lock.lock();
index 419ff5e..cd13f69 100644 (file)
@@ -115,7 +115,7 @@ struct Benchmark {
             }
         }
 
-        sleep(secondsPerTest);
+        sleep(Seconds { secondsPerTest });
         keepGoing = false;
     
         for (unsigned threadIndex = numThreadGroups * numThreadsPerGroup; threadIndex--;)
index f20043a..b898cbd 100644 (file)
@@ -327,7 +327,7 @@ Seconds currentCPUTime()
 #endif
 }
 
-void sleep(double value)
+void sleep(Seconds value)
 {
     // It's very challenging to find portable ways of sleeping for less than a second. On UNIX, you want to
     // use usleep() but it's hard to #include it in a portable way (you'd think it's in unistd.h, but then
@@ -337,7 +337,7 @@ void sleep(double value)
     Lock fakeLock;
     Condition fakeCondition;
     LockHolder fakeLocker(fakeLock);
-    fakeCondition.waitFor(fakeLock, Seconds(value));
+    fakeCondition.waitFor(fakeLock, value);
 }
 
 } // namespace WTF
index afc325f..aeea70f 100644 (file)
@@ -66,12 +66,7 @@ inline double monotonicallyIncreasingTimeMS()
 // than a millisecond.
 WTF_EXPORT_PRIVATE Seconds currentCPUTime();
 
-WTF_EXPORT_PRIVATE void sleep(double);
-
-inline void sleepMS(double value)
-{
-    sleep(value / 1000.0);
-}
+WTF_EXPORT_PRIVATE void sleep(Seconds);
 
 } // namespace WTF
 
@@ -81,6 +76,5 @@ using WTF::currentTimeMS;
 using WTF::monotonicallyIncreasingTime;
 using WTF::monotonicallyIncreasingTimeMS;
 using WTF::sleep;
-using WTF::sleepMS;
 
 #endif // CurrentTime_h
index 12a9c33..32ac379 100644 (file)
@@ -33,7 +33,7 @@
 #define SLEEP_THREAD_FOR_DEBUGGER() \
 do { \
     do { \
-        sleep(1.0); \
+        sleep(1_s); \
         if (WTFIsDebuggerAttached()) \
             break; \
     } while (1); \
index c9d3003..8f7383d 100644 (file)
@@ -69,10 +69,5 @@ void Seconds::dump(PrintStream& out) const
     out.print(m_value, " sec");
 }
 
-void sleep(Seconds value)
-{
-    sleep(value.value());
-}
-
 } // namespace WTF
 
index 9a4798f..079fba7 100644 (file)
@@ -282,8 +282,6 @@ constexpr Seconds operator"" _ns(unsigned long long nanoseconds)
 
 } // inline seconds_literals
 
-WTF_EXPORT_PRIVATE void sleep(Seconds);
-
 } // namespace WTF
 
 namespace std {
index 3d39b1d..5755113 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <wtf/CurrentTime.h>
 #include <wtf/DataLog.h>
 #include <wtf/Locker.h>
 #include <wtf/ProcessID.h>
index 9e83384..4afbc85 100644 (file)
@@ -1,3 +1,17 @@
+2018-02-22  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Remove sleep(double) and sleepMS(double) interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=183038
+
+        Reviewed by Mark Lam.
+
+        * PluginProcess/WebProcessConnection.cpp:
+        (WebKit::WebProcessConnection::createPluginAsynchronously):
+        * UIProcess/linux/MemoryPressureMonitor.cpp:
+        (WebKit::pollIntervalForUsedMemoryPercentage):
+        (WebKit::MemoryPressureMonitor::MemoryPressureMonitor):
+        * WebProcess/wpe/WebProcessMainWPE.cpp:
+
 2018-02-22  Youenn Fablet  <youenn@apple.com>
 
         Add release logging for CacheStorage::Engine disk related functions
index 12a341d..a0a2c24 100644 (file)
@@ -284,7 +284,7 @@ void WebProcessConnection::createPluginAsynchronously(const PluginCreationParame
     uint32_t remoteLayerClientID = 0;
     
     if (creationParameters.artificialPluginInitializationDelayEnabled) {
-        unsigned artificialPluginInitializationDelay = 5;
+        Seconds artificialPluginInitializationDelay { 5_s };
         sleep(artificialPluginInitializationDelay);
     }
 
index a6baba4..a0a8583 100644 (file)
@@ -46,8 +46,8 @@ namespace WebKit {
 
 static const size_t notSet = static_cast<size_t>(-1);
 
-static const double s_minPollingIntervalInSeconds = 1;
-static const double s_maxPollingIntervalInSeconds = 5;
+static const Seconds s_minPollingInterval { 1_s };
+static const Seconds s_maxPollingInterval { 5_s };
 static const double s_minUsedMemoryPercentageForPolling = 50;
 static const double s_maxUsedMemoryPercentageForPolling = 90;
 static const int s_memoryPresurePercentageThreshold = 95;
@@ -198,17 +198,17 @@ static int systemMemoryUsedAsPercentage()
     return ((memoryTotal - memoryAvailable) * 100) / memoryTotal;
 }
 
-static inline double pollIntervalForUsedMemoryPercentage(int usedPercentage)
+static inline Seconds pollIntervalForUsedMemoryPercentage(int usedPercentage)
 {
     // Use a different poll interval depending on the currently memory used,
     // to avoid polling too often when the system is under low memory usage.
     if (usedPercentage < s_minUsedMemoryPercentageForPolling)
-        return s_maxPollingIntervalInSeconds;
+        return s_maxPollingInterval;
 
     if (usedPercentage >= s_maxUsedMemoryPercentageForPolling)
-        return s_minPollingIntervalInSeconds;
+        return s_minPollingInterval;
 
-    return s_minPollingIntervalInSeconds + (s_maxPollingIntervalInSeconds - s_minPollingIntervalInSeconds) *
+    return s_minPollingInterval + (s_maxPollingInterval - s_minPollingInterval) *
         ((usedPercentage - s_minUsedMemoryPercentageForPolling) / (s_maxUsedMemoryPercentageForPolling - s_minUsedMemoryPercentageForPolling));
 }
 
@@ -249,7 +249,7 @@ MemoryPressureMonitor::MemoryPressureMonitor()
         return;
 
     Thread::create("MemoryPressureMonitor", [this] {
-        double pollInterval = s_maxPollingIntervalInSeconds;
+        Seconds pollInterval = s_maxPollingInterval;
         while (true) {
             sleep(pollInterval);
 
index 10153a5..d653859 100644 (file)
@@ -44,7 +44,7 @@ public:
     {
 #if ENABLE(DEVELOPER_MODE)
         if (g_getenv("WEBKIT2_PAUSE_WEB_PROCESS_ON_LAUNCH"))
-            WTF::sleep(30);
+            WTF::sleep(30_s);
 #endif
 
         return true;
index d7b5064..0c97b3c 100644 (file)
@@ -1,3 +1,30 @@
+2018-02-22  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Remove sleep(double) and sleepMS(double) interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=183038
+
+        Reviewed by Mark Lam.
+
+        * DumpRenderTree/TestNetscapePlugIn/PluginTest.cpp:
+        (PluginTest::indicateTestFailure):
+        * DumpRenderTree/TestNetscapePlugIn/Tests/EvaluateJSWithinNPP_New.cpp:
+        (EvaluteJSWithinNPP_New::NPP_New):
+        * DumpRenderTree/TestNetscapePlugIn/Tests/InvokeDestroysPluginWithinNPP_New.cpp:
+        (InvokeDestroysPluginWithinNPP_New::NPP_New):
+        * DumpRenderTree/TestNetscapePlugIn/Tests/SlowNPPNew.cpp:
+        * TestWebKitAPI/Tests/WTF/Signals.cpp:
+        (TEST):
+        * TestWebKitAPI/Tests/WTF/ThreadGroup.cpp:
+        (TestWebKitAPI::testThreadGroup):
+        * TestWebKitAPI/Tests/WTF/WorkQueue.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/PictureInPictureDelegate.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/jsconly/PlatformUtilitiesJSCOnly.cpp:
+        (TestWebKitAPI::Util::sleep):
+
 2018-02-21  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake][Win] Use cmakeconfig.h rather than config.h and Platform.h
index a9d1405..3322aa3 100644 (file)
@@ -28,6 +28,7 @@
 #include "PluginObject.h"
 #include <assert.h>
 #include <string.h>
+#include <wtf/CurrentTime.h>
 #include <wtf/Platform.h>
 #include <wtf/ExportMacros.h>
 
@@ -81,11 +82,7 @@ void PluginTest::indicateTestFailure()
     // This should really be an assert, but there's no way for the test framework
     // to know that the plug-in process crashed, so we'll just sleep for a while
     // to ensure that the test times out.
-#if defined(XP_WIN)
-    ::Sleep(100000);
-#else
-    sleep(1000);
-#endif
+    sleep(1000_s);
 }
 
 NPError PluginTest::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
index c066db5..a142456 100644 (file)
@@ -26,6 +26,7 @@
 #include "PluginTest.h"
 
 #include "PluginObject.h"
+#include <wtf/CurrentTime.h>
 
 using namespace std;
 
@@ -48,7 +49,7 @@ EvaluteJSWithinNPP_New::EvaluteJSWithinNPP_New(NPP npp, const string& identifier
 NPError EvaluteJSWithinNPP_New::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *saved)
 {
     // Give the WebProcess enough time to be deadlocked waiting for the PluginProcess.
-    usleep(15000);
+    sleep(15_ms);
     executeScript("var theLocation = window.location;");
     return NPERR_NO_ERROR;
 }
index 0e2dbdc..9fa9cfc 100644 (file)
@@ -26,6 +26,7 @@
 #include "PluginTest.h"
 
 #include "PluginObject.h"
+#include <wtf/CurrentTime.h>
 
 using namespace std;
 
@@ -48,7 +49,7 @@ InvokeDestroysPluginWithinNPP_New::InvokeDestroysPluginWithinNPP_New(NPP npp, co
 NPError InvokeDestroysPluginWithinNPP_New::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *saved)
 {
     // Give the WebProcess enough time to be deadlocked waiting for the PluginProcess if things aren't working correctly.
-    usleep(15000);
+    sleep(15_ms);
     
     NPObject* windowObject = 0;
     if (NPN_GetValue(NPNVWindowNPObject, &windowObject) != NPERR_NO_ERROR)
index 373736e..321d782 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #include <type_traits>
+#include <wtf/CurrentTime.h>
 #include <wtf/DataLog.h>
 #include <wtf/Threading.h>
 #include <wtf/threads/Signals.h>
@@ -57,7 +58,7 @@ TEST(Signals, SignalsWorkOnExit)
         std::unique_lock<std::mutex> locker(static_cast<ReflectedThread&>(receiverThread.get()).m_mutex);
         receiverShouldKeepRunning.store(false);
         EXPECT_FALSE(static_cast<ReflectedThread&>(receiverThread.get()).hasExited());
-        sleep(1);
+        sleep(1_s);
         signalFired = !pthread_kill(static_cast<ReflectedThread&>(receiverThread.get()).m_handle, std::get<0>(toSystemSignal(Signal::Usr)));
     }
 
index 7551071..291a3f0 100644 (file)
@@ -77,7 +77,7 @@ static void testThreadGroup(Mode mode)
         }
 
         // While holding ThreadGroup lock, threads do not exit.
-        WTF::sleep(0.1);
+        WTF::sleep(100_ms);
         EXPECT_EQ(threadGroup->threads(threadGroupLocker).size(), numberOfThreads);
     }
     {
index 3158c36..5cf1671 100644 (file)
@@ -231,7 +231,7 @@ TEST(WTF_WorkQueue, DestroyOnSelf)
         dispatchAfterTestCompleted.wait(lock, [&] {
             return completed;
         });
-        WTF::sleep(0.1);
+        WTF::sleep(100_ms);
     }
 }
 
index 70ed464..19a8430 100644 (file)
@@ -41,6 +41,7 @@
 #import <WebKit/WKViewPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
+#import <wtf/CurrentTime.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/mac/AppKitCompatibilityDeclarations.h>
 
@@ -137,7 +138,7 @@ TEST(PictureInPicture, WKUIDelegate)
     TestWebKitAPI::Util::run(&hasVideoInPictureInPictureCalled);
     ASSERT_TRUE(hasVideoInPictureInPictureValue);
     
-    sleep(1); // Wait for PIPAgent to launch, or it won't call -pipDidClose: callback.
+    sleep(1_s); // Wait for PIPAgent to launch, or it won't call -pipDidClose: callback.
     
     hasVideoInPictureInPictureCalled = false;
     [webView mouseDown:event];
@@ -185,7 +186,7 @@ TEST(PictureInPicture, WKPageUIClient)
     TestWebKitAPI::Util::run(&hasVideoInPictureInPictureCalled);
     ASSERT_TRUE(hasVideoInPictureInPictureValue);
     
-    sleep(1); // Wait for PIPAgent to launch, or it won't call -pipDidClose: callback.
+    sleep(1_s); // Wait for PIPAgent to launch, or it won't call -pipDidClose: callback.
     
     hasVideoInPictureInPictureCalled = false;
     webView.simulateButtonClick(kWKEventMouseButtonLeftButton, 5, 5, 0);
index dad3906..d197f1d 100644 (file)
@@ -40,6 +40,7 @@
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WebItemProviderPasteboard.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
+#import <wtf/CurrentTime.h>
 
 typedef void (^FileLoadCompletionBlock)(NSURL *, BOOL, NSError *);
 typedef void (^DataLoadCompletionBlock)(NSData *, NSError *);
@@ -1399,7 +1400,7 @@ TEST(DataInteractionTests, WebItemProviderPasteboardLoading)
     auto slowItem = adoptNS([[UIItemProvider alloc] init]);
     [slowItem registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeUTF8PlainText options:nil loadHandler:^NSProgress *(UIItemProviderDataLoadCompletionBlock completionBlock)
     {
-        sleep(2);
+        sleep(2_s);
         completionBlock([slowString dataUsingEncoding:NSUTF8StringEncoding], nil);
         return nil;
     }];
index 41dc6b9..f78e88e 100644 (file)
@@ -50,7 +50,7 @@ void run(bool* done)
 
 void sleep(double seconds)
 {
-    WTF::sleep(seconds);
+    WTF::sleep(Seconds { seconds });
 }
 
 } // namespace Util