Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: src/cancelable-task.h

Issue 1409993012: Add {CancelableTaskManager} to handle {Cancelable} concurrent tasks. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: First try: incomplete/blocking Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/cancelable-task.cc » ('j') | src/cancelable-task.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cancelable-task.h
diff --git a/src/cancelable-task.h b/src/cancelable-task.h
index bae5b580cd2330897f0e9d5aa71d415cfecccd1d..53c44a091e9bd3dc10f1fb7d51537220f9c08a6a 100644
--- a/src/cancelable-task.h
+++ b/src/cancelable-task.h
@@ -6,6 +6,7 @@
#define V8_CANCELABLE_TASK_H_
#include "include/v8-platform.h"
+#include "src/atomic-utils.h"
#include "src/base/macros.h"
namespace v8 {
@@ -13,19 +14,40 @@ namespace internal {
class Isolate;
-
+// {Cancelable} can be used to create tasks that can run on foreground and
+// background workers and can be canceled from any of those.
class Cancelable {
public:
explicit Cancelable(Isolate* isolate);
virtual ~Cancelable();
- virtual void Cancel() { is_cancelled_ = true; }
+ bool Cancel() { return status_.TrySetValue(kWaiting, kCanceled); }
+ bool IsCanceled() { return status_.Value() == kCanceled; }
+ bool IsRunning() { return status_.Value() == kRunning; }
protected:
+ // Before actually running, the task needs to call {CanRun} to indicate that
+ // it cannot be canceled anymore.
+ bool CanRun() { return status_.TrySetValue(kWaiting, kRunning); }
Hannes Payer (out of office) 2015/11/04 23:19:00 I think TryRun matches better the semantics.
+
Isolate* isolate_;
- bool is_cancelled_;
private:
+ enum Status {
+ kWaiting,
+ kCanceled,
+ kRunning,
+ kCanceledForShutdown,
+ };
+
+ bool CancelForShutdown() {
+ return status_.TrySetValue(kWaiting, kCanceledForShutdown);
+ }
+
+ AtomicValue<Status> status_;
+
+ friend class Isolate;
Hannes Payer (out of office) 2015/11/04 23:19:00 Why friends?
+
DISALLOW_COPY_AND_ASSIGN(Cancelable);
};
@@ -37,7 +59,7 @@ class CancelableTask : public Cancelable, public Task {
// Task overrides.
void Run() final {
- if (!is_cancelled_) {
+ if (CanRun()) {
RunInternal();
}
}
@@ -56,7 +78,7 @@ class CancelableIdleTask : public Cancelable, public IdleTask {
// IdleTask overrides.
void Run(double deadline_in_seconds) final {
- if (!is_cancelled_) {
+ if (CanRun()) {
RunInternal(deadline_in_seconds);
}
}
« no previous file with comments | « no previous file | src/cancelable-task.cc » ('j') | src/cancelable-task.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698