2015-07-20 15:03:51 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_CANCELABLE_TASK_H_
|
|
|
|
#define V8_CANCELABLE_TASK_H_
|
|
|
|
|
|
|
|
#include "include/v8-platform.h"
|
|
|
|
#include "src/base/macros.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class Isolate;
|
|
|
|
|
2015-07-30 14:09:01 +00:00
|
|
|
|
|
|
|
class Cancelable {
|
2015-07-20 15:03:51 +00:00
|
|
|
public:
|
2015-07-30 14:09:01 +00:00
|
|
|
explicit Cancelable(Isolate* isolate);
|
|
|
|
virtual ~Cancelable();
|
|
|
|
|
|
|
|
virtual void Cancel() { is_cancelled_ = true; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Isolate* isolate_;
|
|
|
|
bool is_cancelled_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Cancelable);
|
|
|
|
};
|
2015-07-20 15:03:51 +00:00
|
|
|
|
|
|
|
|
2015-07-30 14:09:01 +00:00
|
|
|
// 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.
|
2015-07-20 15:03:51 +00:00
|
|
|
void Run() final {
|
|
|
|
if (!is_cancelled_) {
|
|
|
|
RunInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void RunInternal() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CancelableTask);
|
|
|
|
};
|
|
|
|
|
2015-07-30 14:09:01 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-20 15:03:51 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_CANCELABLE_TASK_H_
|