v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
etw-isolate-capture-state-monitor-win.cc
Go to the documentation of this file.
1// Copyright 2024 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
6
11
12namespace v8 {
13namespace internal {
14namespace ETWJITInterface {
15
17 base::Mutex* mutex, size_t pending_isolate_count)
18 : mutex_(mutex), pending_isolate_count_(pending_isolate_count) {}
19
22 base::TimeDelta remaining = delta;
23
24 if (pending_isolate_count_ == 0) {
25 return true;
26 }
27
28 ETWTRACEDBG << "Waiting for " << pending_isolate_count_
29 << " isolates for up to " << remaining.InMilliseconds()
30 << std::endl;
31 while (isolates_ready_cv_.WaitFor(mutex_, remaining)) {
32 ETWTRACEDBG << "WaitFor woke up: " << pending_isolate_count_
33 << " isolates remaining " << std::endl;
34 if (pending_isolate_count_ == 0) {
35 return true;
36 }
37
38 // If the timeout has expired, return false.
39 auto elapsed = base::TimeTicks::Now() - wait_started_;
40 if (elapsed >= remaining) {
41 ETWTRACEDBG << "Elapsed is " << elapsed.InMilliseconds()
42 << " greater than reminaing " << remaining.InMilliseconds()
43 << std::endl;
44 return false;
45 }
46
47 // If the condition variable was woken up spuriously, adjust the timeout.
48 remaining -= elapsed;
49 ETWTRACEDBG << "New remaining " << remaining.InMilliseconds()
50 << " resuming waiting" << std::endl;
51 }
52
53 // Propagate the WaitFor false return value (timeout before being notified) to
54 // the caller.
55 return false;
56}
57
59 {
60 ETWTRACEDBG << "Notify taking mutex" << std::endl;
63 ETWTRACEDBG << "Got mutex and isolate count reduced to "
64 << pending_isolate_count_ << std::endl;
65 }
66 ETWTRACEDBG << "Released mutex preparing to notifyOne " << std::endl;
68 ETWTRACEDBG << "Finished notifyOne " << std::endl;
69}
70
71} // namespace ETWJITInterface
72} // namespace internal
73} // namespace v8
bool WaitFor(Mutex *mutex, const TimeDelta &rel_time) V8_WARN_UNUSED_RESULT
int64_t InMilliseconds() const
Definition time.cc:234
static TimeTicks Now()
Definition time.cc:736
EtwIsolateCaptureStateMonitor(base::Mutex *mutex, size_t pending_isolate_count)
base::Mutex & mutex_
#define ETWTRACEDBG
base::Mutex mutex