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
12
namespace
cppgc
{
13
namespace
internal
{
14
15
// A handle that is used for cancelling individual tasks.
16
struct
SingleThreadedHandle
{
17
struct
NonEmptyTag
{};
18
19
// Default construction results in empty handle.
20
SingleThreadedHandle
() =
default
;
21
22
explicit
SingleThreadedHandle
(
NonEmptyTag
)
23
:
is_cancelled_
(
std
::make_shared<bool>(false)) {}
24
25
void
Cancel
() {
26
DCHECK
(
is_cancelled_
);
27
*
is_cancelled_
=
true
;
28
}
29
30
void
CancelIfNonEmpty
() {
31
if
(
is_cancelled_
) {
32
*
is_cancelled_
=
true
;
33
}
34
}
35
36
bool
IsCanceled
()
const
{
37
DCHECK
(
is_cancelled_
);
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_
cppgc
Definition
cross-heap-remembered-set.h:14
std
STL namespace.
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
logging.h
DCHECK
#define DCHECK(condition)
Definition
logging.h:482
cppgc::internal::SingleThreadedHandle::NonEmptyTag
Definition
task-handle.h:17
cppgc::internal::SingleThreadedHandle
Definition
task-handle.h:16
cppgc::internal::SingleThreadedHandle::IsCanceled
bool IsCanceled() const
Definition
task-handle.h:36
cppgc::internal::SingleThreadedHandle::SingleThreadedHandle
SingleThreadedHandle(NonEmptyTag)
Definition
task-handle.h:22
cppgc::internal::SingleThreadedHandle::SingleThreadedHandle
SingleThreadedHandle()=default
cppgc::internal::SingleThreadedHandle::is_cancelled_
std::shared_ptr< bool > is_cancelled_
Definition
task-handle.h:47
cppgc::internal::SingleThreadedHandle::CancelIfNonEmpty
void CancelIfNonEmpty()
Definition
task-handle.h:30
cppgc::internal::SingleThreadedHandle::Cancel
void Cancel()
Definition
task-handle.h:25
src
heap
cppgc
task-handle.h
Generated on Sun Apr 6 2025 21:08:54 for v8 by
1.12.0