Add CancelableIdleTask.
authorulan <ulan@chromium.org>
Thu, 30 Jul 2015 14:09:01 +0000 (07:09 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 30 Jul 2015 14:09:14 +0000 (14:09 +0000)
BUG=chromium:490559
LOG=NO

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

Cr-Commit-Position: refs/heads/master@{#29935}

src/cancelable-task.cc
src/cancelable-task.h
src/isolate.cc
src/isolate.h

index 5eab9605b4a3c692b6ce58dd4ce51a148e7bd072..32d5057c49ead4149d9487e91a12cf8cdd304cd0 100644 (file)
@@ -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);
   }
index 1a15e248efe8bf555b4f4e6db6e0ca73e7b1a76a..bae5b580cd2330897f0e9d5aa71d415cfecccd1d 100644 (file)
@@ -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
 
index 15b16fc5df084860991c45cede3574d5a23c9985..aa67185e26fda26d87447525921694c4f7bad6ae 100644 (file)
@@ -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);
index 585c5b8bf2f5f54bb3013bdcdff0538c12318c64..a11f75ab290a1ce82439fa89c5508f3167e567bb 100644 (file)
@@ -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;