Add IdleTask API to v8::Platform.
BUG=chromium:490559 LOG=NO Review URL: https://codereview.chromium.org/1225713003 Cr-Commit-Position: refs/heads/master@{#29676}
This commit is contained in:
parent
199e30d36f
commit
a9c7712eb8
@ -19,6 +19,20 @@ class Task {
|
|||||||
virtual void Run() = 0;
|
virtual void Run() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An IdleTask represents a unit of work to be performed in idle time.
|
||||||
|
* The Run method is invoked with an argument that specifies the deadline in
|
||||||
|
* seconds returned by MonotonicallyIncreasingTime().
|
||||||
|
* The idle task is expected to complete by this deadline.
|
||||||
|
*/
|
||||||
|
class IdleTask {
|
||||||
|
public:
|
||||||
|
virtual ~IdleTask() {}
|
||||||
|
virtual void Run(double deadline_in_seconds) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* V8 Platform abstraction layer.
|
* V8 Platform abstraction layer.
|
||||||
*
|
*
|
||||||
@ -63,10 +77,28 @@ class Platform {
|
|||||||
* scheduling. The definition of "foreground" is opaque to V8.
|
* scheduling. The definition of "foreground" is opaque to V8.
|
||||||
*/
|
*/
|
||||||
virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
||||||
double delay_in_seconds) {
|
double delay_in_seconds) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules a task to be invoked on a foreground thread wrt a specific
|
||||||
|
* |isolate| when the embedder is idle.
|
||||||
|
* Requires that SupportsIdleTasks(isolate) is true.
|
||||||
|
* Idle tasks may be reordered relative to other task types and may be
|
||||||
|
* starved for an arbitrarily long time if no idle time is available.
|
||||||
|
* The definition of "foreground" is opaque to V8.
|
||||||
|
*/
|
||||||
|
virtual void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) {
|
||||||
// TODO(ulan): Make this function abstract after V8 roll in Chromium.
|
// TODO(ulan): Make this function abstract after V8 roll in Chromium.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if idle tasks are enabled for the given |isolate|.
|
||||||
|
*/
|
||||||
|
virtual bool IdleTasksEnabled(Isolate* isolate) {
|
||||||
|
// TODO(ulan): Make this function abstract after V8 roll in Chromium.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monotonically increasing time in seconds from an arbitrary fixed point in
|
* Monotonically increasing time in seconds from an arbitrary fixed point in
|
||||||
* the past. This function is expected to return at least
|
* the past. This function is expected to return at least
|
||||||
|
@ -155,6 +155,15 @@ void DefaultPlatform::CallDelayedOnForegroundThread(Isolate* isolate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DefaultPlatform::CallIdleOnForegroundThread(Isolate* isolate,
|
||||||
|
IdleTask* task) {
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DefaultPlatform::IdleTasksEnabled(Isolate* isolate) { return false; }
|
||||||
|
|
||||||
|
|
||||||
double DefaultPlatform::MonotonicallyIncreasingTime() {
|
double DefaultPlatform::MonotonicallyIncreasingTime() {
|
||||||
return base::TimeTicks::HighResolutionNow().ToInternalValue() /
|
return base::TimeTicks::HighResolutionNow().ToInternalValue() /
|
||||||
static_cast<double>(base::Time::kMicrosecondsPerSecond);
|
static_cast<double>(base::Time::kMicrosecondsPerSecond);
|
||||||
|
@ -40,6 +40,9 @@ class DefaultPlatform : public Platform {
|
|||||||
Task* task) override;
|
Task* task) override;
|
||||||
virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
||||||
double delay_in_seconds) override;
|
double delay_in_seconds) override;
|
||||||
|
virtual void CallIdleOnForegroundThread(Isolate* isolate,
|
||||||
|
IdleTask* task) override;
|
||||||
|
virtual bool IdleTasksEnabled(Isolate* isolate) override;
|
||||||
double MonotonicallyIncreasingTime() override;
|
double MonotonicallyIncreasingTime() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user