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);
}
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();
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
delete basic_block_profiler_;
basic_block_profiler_ = NULL;
- for (CancelableTask* task : cancelable_tasks_) {
+ for (Cancelable* task : cancelable_tasks_) {
task->Cancel();
}
cancelable_tasks_.clear();
}
-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);
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);
FutexWaitListNode futex_wait_list_node_;
- std::set<CancelableTask*> cancelable_tasks_;
+ std::set<Cancelable*> cancelable_tasks_;
friend class ExecutionAccess;
friend class HandleScopeImplementer;