Commit 0dc4c959 authored by ulan's avatar ulan Committed by Commit bot

Add CancelableIdleTask.

BUG=chromium:490559
LOG=NO

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

Cr-Commit-Position: refs/heads/master@{#29935}
parent 4da6cbd9
......@@ -11,13 +11,13 @@ namespace v8 {
namespace internal {
CancelableTask::CancelableTask(Isolate* isolate)
Cancelable::Cancelable(Isolate* isolate)
: isolate_(isolate), is_cancelled_(false) {
isolate->RegisterCancelableTask(this);
}
CancelableTask::~CancelableTask() {
Cancelable::~Cancelable() {
if (!is_cancelled_) {
isolate_->RemoveCancelableTask(this);
}
......
......@@ -13,13 +13,29 @@ namespace internal {
class Isolate;
class CancelableTask : public Task {
class Cancelable {
public:
explicit CancelableTask(Isolate* isolate);
~CancelableTask() override;
explicit Cancelable(Isolate* isolate);
virtual ~Cancelable();
virtual void Cancel() { is_cancelled_ = true; }
protected:
Isolate* isolate_;
bool is_cancelled_;
private:
DISALLOW_COPY_AND_ASSIGN(Cancelable);
};
void Cancel() { is_cancelled_ = true; }
// Multiple inheritance can be used because Task is a pure interface.
class CancelableTask : public Cancelable, public Task {
public:
explicit CancelableTask(Isolate* isolate) : Cancelable(isolate) {}
// Task overrides.
void Run() final {
if (!is_cancelled_) {
RunInternal();
......@@ -28,15 +44,30 @@ class CancelableTask : public Task {
virtual void RunInternal() = 0;
protected:
Isolate* isolate_;
private:
bool is_cancelled_;
DISALLOW_COPY_AND_ASSIGN(CancelableTask);
};
// Multiple inheritance can be used because IdleTask is a pure interface.
class CancelableIdleTask : public Cancelable, public IdleTask {
public:
explicit CancelableIdleTask(Isolate* isolate) : Cancelable(isolate) {}
// IdleTask overrides.
void Run(double deadline_in_seconds) final {
if (!is_cancelled_) {
RunInternal(deadline_in_seconds);
}
}
virtual void RunInternal(double deadline_in_seconds) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask);
};
} // namespace internal
} // namespace v8
......
......@@ -1908,7 +1908,7 @@ void Isolate::Deinit() {
delete basic_block_profiler_;
basic_block_profiler_ = NULL;
for (CancelableTask* task : cancelable_tasks_) {
for (Cancelable* task : cancelable_tasks_) {
task->Cancel();
}
cancelable_tasks_.clear();
......@@ -2790,12 +2790,12 @@ void Isolate::CheckDetachedContextsAfterGC() {
}
void Isolate::RegisterCancelableTask(CancelableTask* task) {
void Isolate::RegisterCancelableTask(Cancelable* task) {
cancelable_tasks_.insert(task);
}
void Isolate::RemoveCancelableTask(CancelableTask* task) {
void Isolate::RemoveCancelableTask(Cancelable* task) {
auto removed = cancelable_tasks_.erase(task);
USE(removed);
DCHECK(removed == 1);
......
......@@ -1139,8 +1139,8 @@ class Isolate {
FutexWaitListNode* futex_wait_list_node() { return &futex_wait_list_node_; }
void RegisterCancelableTask(CancelableTask* task);
void RemoveCancelableTask(CancelableTask* task);
void RegisterCancelableTask(Cancelable* task);
void RemoveCancelableTask(Cancelable* task);
protected:
explicit Isolate(bool enable_serializer);
......@@ -1379,7 +1379,7 @@ class Isolate {
FutexWaitListNode futex_wait_list_node_;
std::set<CancelableTask*> cancelable_tasks_;
std::set<Cancelable*> cancelable_tasks_;
friend class ExecutionAccess;
friend class HandleScopeImplementer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment