v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
task-handle.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_CPPGC_TASK_HANDLE_H_
6#define V8_HEAP_CPPGC_TASK_HANDLE_H_
7
8#include <memory>
9
10#include "src/base/logging.h"
11
12namespace cppgc {
13namespace internal {
14
15// A handle that is used for cancelling individual tasks.
17 struct NonEmptyTag {};
18
19 // Default construction results in empty handle.
21
23 : is_cancelled_(std::make_shared<bool>(false)) {}
24
25 void Cancel() {
27 *is_cancelled_ = true;
28 }
29
31 if (is_cancelled_) {
32 *is_cancelled_ = true;
33 }
34 }
35
36 bool IsCanceled() const {
38 return *is_cancelled_;
39 }
40
41 // A handle is active if it is non-empty and not cancelled.
42 explicit operator bool() const {
43 return is_cancelled_.get() && !*is_cancelled_.get();
44 }
45
46 private:
47 std::shared_ptr<bool> is_cancelled_;
48};
49
50} // namespace internal
51} // namespace cppgc
52
53#endif // V8_HEAP_CPPGC_TASK_HANDLE_H_
STL namespace.
#define DCHECK(condition)
Definition logging.h:482
std::shared_ptr< bool > is_cancelled_
Definition task-handle.h:47