Add MonotonicallyIncreasingTime to V8 Platform.
authorrmcilroy@chromium.org <rmcilroy@chromium.org>
Mon, 6 Oct 2014 12:22:25 +0000 (12:22 +0000)
committerrmcilroy@chromium.org <rmcilroy@chromium.org>
Mon, 6 Oct 2014 12:22:25 +0000 (12:22 +0000)
Adds a MonotonicallyIncreasingTime() function to the Platform API to enable the
embedder to provide a time API to V8 which will be used for IdleNotification deadlines.

BUG=417668
LOG=Y
R=jochen@chromium.org

Review URL: https://codereview.chromium.org/632663002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24411 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8-platform.h
src/libplatform/default-platform.cc
src/libplatform/default-platform.h

index 1f1679f0e0b60ec7e36281e480cb20d8c8cad64b..7bac11aef069957fc7e22b0a437becdac44b8148 100644 (file)
@@ -55,6 +55,20 @@ class Platform {
    * scheduling. The definition of "foreground" is opaque to V8.
    */
   virtual void CallOnForegroundThread(Isolate* isolate, Task* task) = 0;
+
+
+  /**
+   * Monotonically increasing time in seconds from an arbitrary fixed point in
+   * the past. This function is expected to return at least
+   * millisecond-precision values. For this reason,
+   * it is recommended that the fixed point be no further in the past than
+   * the epoch.
+   **/
+  virtual double MonotonicallyIncreasingTime() {
+    // TODO(rmcilroy): Remove this default implementation when Chromium
+    // change has landed.
+    return 0;
+  }
 };
 
 }  // namespace v8
index b5b8571dbc9a9e4d059d91bb641bf5a6ff81f858..1ac52f919f3f4889037512e332a5b07fba25146c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "src/base/logging.h"
 #include "src/base/platform/platform.h"
+#include "src/base/platform/time.h"
 #include "src/base/sys-info.h"
 #include "src/libplatform/worker-thread.h"
 
@@ -106,4 +107,9 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
   main_thread_queue_[isolate].push(task);
 }
 
+
+double DefaultPlatform::MonotonicallyIncreasingTime() {
+  return base::TimeTicks::HighResolutionNow().ToInternalValue() /
+         static_cast<double>(base::Time::kMicrosecondsPerSecond);
+}
 } }  // namespace v8::platform
index 1efd7b24fe8807275ba3a357795a21837e6179fc..552949826a4ea105364ea2b33d6f482d71ffaa89 100644 (file)
@@ -37,6 +37,7 @@ class DefaultPlatform : public Platform {
       Task* task, ExpectedRuntime expected_runtime) OVERRIDE;
   virtual void CallOnForegroundThread(v8::Isolate* isolate,
                                       Task* task) OVERRIDE;
+  virtual double MonotonicallyIncreasingTime() OVERRIDE;
 
  private:
   static const int kMaxThreadPoolSize;