v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
parked-scope-inl.h
Go to the documentation of this file.
1// Copyright 2023 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_PARKED_SCOPE_INL_H_
6#define V8_HEAP_PARKED_SCOPE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
16
17namespace v8 {
18namespace internal {
19
23
26 : mutex_(mutex) {
27 DCHECK(AllowGarbageCollection::IsAllowed());
28 if (!mutex_->TryLock()) {
29 local_heap->ExecuteWhileParked([this]() { mutex_->Lock(); });
30 }
31}
32
36
39 : mutex_(mutex) {
40 DCHECK(AllowGarbageCollection::IsAllowed());
41 if (!mutex_->TryLock()) {
42 local_heap->ExecuteWhileParked([this]() { mutex_->Lock(); });
43 }
44}
45
48 bool enable_mutex)
49 : ParkedMutexGuardIf(local_isolate -> heap(), mutex, enable_mutex) {}
52 bool enable_mutex) {
53 DCHECK(AllowGarbageCollection::IsAllowed());
54 if (!enable_mutex) return;
55 mutex_ = mutex;
56
57 if (!mutex_->TryLock()) {
58 local_heap->ExecuteWhileParked([this]() { mutex_->Lock(); });
59 }
60}
61
66
69 local_heap->ExecuteWhileParked(
70 [this, mutex](const ParkedScope& parked) { ParkedWait(parked, mutex); });
71}
72
74 LocalIsolate* local_isolate, base::Mutex* mutex,
75 const base::TimeDelta& rel_time) {
76 return ParkedWaitFor(local_isolate->heap(), mutex, rel_time);
77}
78
80 LocalHeap* local_heap, base::Mutex* mutex,
81 const base::TimeDelta& rel_time) {
82 bool result;
83 local_heap->ExecuteWhileParked(
84 [this, mutex, rel_time, &result](const ParkedScope& parked) {
85 result = ParkedWaitFor(parked, mutex, rel_time);
86 });
87 return result;
88}
89
91 ParkedWait(local_isolate->heap());
92}
93
95 local_heap->ExecuteWhileParked(
96 [this](const ParkedScope& parked) { ParkedWait(parked); });
97}
98
100 LocalIsolate* local_isolate, const base::TimeDelta& rel_time) {
101 return ParkedWaitFor(local_isolate->heap(), rel_time);
102}
103
105 LocalHeap* local_heap, const base::TimeDelta& rel_time) {
106 bool result;
107 local_heap->ExecuteWhileParked(
108 [this, rel_time, &result](const ParkedScope& parked) {
109 result = ParkedWaitFor(parked, rel_time);
110 });
111 return result;
112}
113
115 ParkedJoin(local_isolate->heap());
116}
117
119 local_heap->ExecuteWhileParked(
120 [this](const ParkedScope& parked) { ParkedJoin(parked); });
121}
122
123template <typename ThreadCollection>
124// static
126 const ThreadCollection& threads) {
127 ParkedJoinAll(local_isolate->heap(), threads);
128}
129
130template <typename ThreadCollection>
131// static
133 const ThreadCollection& threads) {
134 local_heap->ExecuteWhileParked([&threads](const ParkedScope& parked) {
135 ParkedJoinAll(parked, threads);
136 });
137}
138
139} // namespace internal
140} // namespace v8
141
142#endif // V8_HEAP_PARKED_SCOPE_INL_H_
bool TryLock() V8_WARN_UNUSED_RESULT
Definition mutex.cc:72
void Lock()
Definition mutex.cc:62
bool TryLock() V8_WARN_UNUSED_RESULT
Definition mutex.cc:39
V8_INLINE void ExecuteWhileParked(Callback callback)
V8_INLINE ParkedMutexGuardIf(LocalIsolate *local_isolate, base::Mutex *mutex, bool enable_mutex)
V8_INLINE ParkedMutexGuard(LocalIsolate *local_isolate, base::Mutex *mutex)
V8_INLINE ParkedRecursiveMutexGuard(LocalIsolate *local_isolate, base::RecursiveMutex *mutex)
V8_INLINE bool ParkedWaitFor(LocalIsolate *local_isolate, base::Mutex *mutex, const base::TimeDelta &rel_time) V8_WARN_UNUSED_RESULT
V8_INLINE void ParkedWait(LocalIsolate *local_isolate, base::Mutex *mutex)
V8_INLINE void ParkedWait(LocalIsolate *local_isolate)
V8_INLINE bool ParkedWaitFor(LocalIsolate *local_isolate, const base::TimeDelta &rel_time) V8_WARN_UNUSED_RESULT
V8_INLINE void ParkedJoin(LocalIsolate *local_isolate)
static V8_INLINE void ParkedJoinAll(LocalIsolate *local_isolate, const ThreadCollection &threads)
base::Mutex & mutex_
ZoneVector< RpoNumber > & result
base::Mutex mutex
#define DCHECK(condition)
Definition logging.h:482
#define V8_INLINE
Definition v8config.h:500