From: ulan Date: Thu, 30 Jul 2015 14:09:01 +0000 (-0700) Subject: Add CancelableIdleTask. X-Git-Tag: upstream/4.7.83~1105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0dc4c959336cfd02bcb203974bc44e4633492e58;p=platform%2Fupstream%2Fv8.git Add CancelableIdleTask. BUG=chromium:490559 LOG=NO Review URL: https://codereview.chromium.org/1258923010 Cr-Commit-Position: refs/heads/master@{#29935} --- diff --git a/src/cancelable-task.cc b/src/cancelable-task.cc index 5eab960..32d5057 100644 --- a/src/cancelable-task.cc +++ b/src/cancelable-task.cc @@ -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); } diff --git a/src/cancelable-task.h b/src/cancelable-task.h index 1a15e24..bae5b58 100644 --- a/src/cancelable-task.h +++ b/src/cancelable-task.h @@ -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 diff --git a/src/isolate.cc b/src/isolate.cc index 15b16fc..aa67185 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -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); diff --git a/src/isolate.h b/src/isolate.h index 585c5b8..a11f75a 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -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 cancelable_tasks_; + std::set cancelable_tasks_; friend class ExecutionAccess; friend class HandleScopeImplementer;