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 { ...@@ -11,13 +11,13 @@ namespace v8 {
namespace internal { namespace internal {
CancelableTask::CancelableTask(Isolate* isolate) Cancelable::Cancelable(Isolate* isolate)
: isolate_(isolate), is_cancelled_(false) { : isolate_(isolate), is_cancelled_(false) {
isolate->RegisterCancelableTask(this); isolate->RegisterCancelableTask(this);
} }
CancelableTask::~CancelableTask() { Cancelable::~Cancelable() {
if (!is_cancelled_) { if (!is_cancelled_) {
isolate_->RemoveCancelableTask(this); isolate_->RemoveCancelableTask(this);
} }
......
...@@ -13,13 +13,29 @@ namespace internal { ...@@ -13,13 +13,29 @@ namespace internal {
class Isolate; class Isolate;
class CancelableTask : public Task {
class Cancelable {
public: public:
explicit CancelableTask(Isolate* isolate); explicit Cancelable(Isolate* isolate);
~CancelableTask() override; 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 { void Run() final {
if (!is_cancelled_) { if (!is_cancelled_) {
RunInternal(); RunInternal();
...@@ -28,15 +44,30 @@ class CancelableTask : public Task { ...@@ -28,15 +44,30 @@ class CancelableTask : public Task {
virtual void RunInternal() = 0; virtual void RunInternal() = 0;
protected:
Isolate* isolate_;
private: private:
bool is_cancelled_;
DISALLOW_COPY_AND_ASSIGN(CancelableTask); 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 internal
} // namespace v8 } // namespace v8
......
...@@ -1908,7 +1908,7 @@ void Isolate::Deinit() { ...@@ -1908,7 +1908,7 @@ void Isolate::Deinit() {
delete basic_block_profiler_; delete basic_block_profiler_;
basic_block_profiler_ = NULL; basic_block_profiler_ = NULL;
for (CancelableTask* task : cancelable_tasks_) { for (Cancelable* task : cancelable_tasks_) {
task->Cancel(); task->Cancel();
} }
cancelable_tasks_.clear(); cancelable_tasks_.clear();
...@@ -2790,12 +2790,12 @@ void Isolate::CheckDetachedContextsAfterGC() { ...@@ -2790,12 +2790,12 @@ void Isolate::CheckDetachedContextsAfterGC() {
} }
void Isolate::RegisterCancelableTask(CancelableTask* task) { void Isolate::RegisterCancelableTask(Cancelable* task) {
cancelable_tasks_.insert(task); cancelable_tasks_.insert(task);
} }
void Isolate::RemoveCancelableTask(CancelableTask* task) { void Isolate::RemoveCancelableTask(Cancelable* task) {
auto removed = cancelable_tasks_.erase(task); auto removed = cancelable_tasks_.erase(task);
USE(removed); USE(removed);
DCHECK(removed == 1); DCHECK(removed == 1);
......
...@@ -1139,8 +1139,8 @@ class Isolate { ...@@ -1139,8 +1139,8 @@ class Isolate {
FutexWaitListNode* futex_wait_list_node() { return &futex_wait_list_node_; } FutexWaitListNode* futex_wait_list_node() { return &futex_wait_list_node_; }
void RegisterCancelableTask(CancelableTask* task); void RegisterCancelableTask(Cancelable* task);
void RemoveCancelableTask(CancelableTask* task); void RemoveCancelableTask(Cancelable* task);
protected: protected:
explicit Isolate(bool enable_serializer); explicit Isolate(bool enable_serializer);
...@@ -1379,7 +1379,7 @@ class Isolate { ...@@ -1379,7 +1379,7 @@ class Isolate {
FutexWaitListNode futex_wait_list_node_; FutexWaitListNode futex_wait_list_node_;
std::set<CancelableTask*> cancelable_tasks_; std::set<Cancelable*> cancelable_tasks_;
friend class ExecutionAccess; friend class ExecutionAccess;
friend class HandleScopeImplementer; 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