v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
task-queue.cc
Go to the documentation of this file.
1
// Copyright 2013 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
#include "
src/libplatform/task-queue.h
"
6
7
#include "
include/v8-platform.h
"
8
#include "
src/base/logging.h
"
9
#include "
src/base/platform/platform.h
"
10
#include "
src/base/platform/time.h
"
11
12
namespace
v8
{
13
namespace
platform {
14
15
TaskQueue::TaskQueue
() : process_queue_semaphore_(0), terminated_(false) {}
16
17
18
TaskQueue::~TaskQueue
() {
19
base::MutexGuard
guard(&
lock_
);
20
DCHECK
(
terminated_
);
21
DCHECK
(
task_queue_
.empty());
22
}
23
24
void
TaskQueue::Append
(std::unique_ptr<Task> task) {
25
base::MutexGuard
guard(&
lock_
);
26
DCHECK
(!
terminated_
);
27
task_queue_
.push(std::move(task));
28
process_queue_semaphore_
.
Signal
();
29
}
30
31
std::unique_ptr<Task>
TaskQueue::GetNext
() {
32
for
(;;) {
33
{
34
base::MutexGuard
guard(&
lock_
);
35
if
(!
task_queue_
.empty()) {
36
std::unique_ptr<Task>
result
= std::move(
task_queue_
.front());
37
task_queue_
.pop();
38
return
result
;
39
}
40
if
(
terminated_
) {
41
process_queue_semaphore_
.
Signal
();
42
return
nullptr
;
43
}
44
}
45
process_queue_semaphore_
.
Wait
();
46
}
47
}
48
49
50
void
TaskQueue::Terminate
() {
51
base::MutexGuard
guard(&
lock_
);
52
DCHECK
(!
terminated_
);
53
terminated_
=
true
;
54
process_queue_semaphore_
.
Signal
();
55
}
56
57
void
TaskQueue::BlockUntilQueueEmptyForTesting
() {
58
for
(;;) {
59
{
60
base::MutexGuard
guard(&
lock_
);
61
if
(
task_queue_
.empty())
return
;
62
}
63
base::OS::Sleep
(
base::TimeDelta::FromMilliseconds
(5));
64
}
65
}
66
67
}
// namespace platform
68
}
// namespace v8
v8::base::LockGuard
Definition
mutex.h:192
v8::base::OS::Sleep
static void Sleep(TimeDelta interval)
Definition
platform-posix.cc:719
v8::base::Semaphore::Signal
void Signal()
v8::base::Semaphore::Wait
void Wait()
v8::base::TimeDelta::FromMilliseconds
static constexpr TimeDelta FromMilliseconds(int64_t milliseconds)
Definition
time.h:84
v8::platform::TaskQueue::GetNext
std::unique_ptr< Task > GetNext()
Definition
task-queue.cc:31
v8::platform::TaskQueue::task_queue_
std::queue< std::unique_ptr< Task > > task_queue_
Definition
task-queue.h:47
v8::platform::TaskQueue::terminated_
bool terminated_
Definition
task-queue.h:48
v8::platform::TaskQueue::TaskQueue
TaskQueue()
Definition
task-queue.cc:15
v8::platform::TaskQueue::~TaskQueue
~TaskQueue()
Definition
task-queue.cc:18
v8::platform::TaskQueue::Terminate
void Terminate()
Definition
task-queue.cc:50
v8::platform::TaskQueue::lock_
base::Mutex lock_
Definition
task-queue.h:46
v8::platform::TaskQueue::Append
void Append(std::unique_ptr< Task > task)
Definition
task-queue.cc:24
v8::platform::TaskQueue::BlockUntilQueueEmptyForTesting
void BlockUntilQueueEmptyForTesting()
Definition
task-queue.cc:57
v8::platform::TaskQueue::process_queue_semaphore_
base::Semaphore process_queue_semaphore_
Definition
task-queue.h:45
result
ZoneVector< RpoNumber > & result
Definition
jump-threading.cc:21
v8
Definition
api-arguments-inl.h:19
logging.h
DCHECK
#define DCHECK(condition)
Definition
logging.h:482
platform.h
task-queue.h
time.h
v8-platform.h
src
libplatform
task-queue.cc
Generated on Sun Apr 6 2025 21:08:54 for v8 by
1.12.0