v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
index-generator.cc
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
#include "
src/heap/index-generator.h
"
6
7
#include <optional>
8
9
namespace
v8
{
10
namespace
internal
{
11
12
IndexGenerator::IndexGenerator
(
size_t
size) : first_use_(size > 0) {
13
if
(size == 0)
return
;
14
base::MutexGuard
guard(&
lock_
);
15
ranges_to_split_
.emplace(0, size);
16
}
17
18
std::optional<size_t>
IndexGenerator::GetNext
() {
19
base::MutexGuard
guard(&
lock_
);
20
if
(
first_use_
) {
21
first_use_
=
false
;
22
return
0;
23
}
24
if
(
ranges_to_split_
.empty())
return
std::nullopt;
25
26
// Split the oldest running range in 2 and return the middle index as
27
// starting point.
28
auto
range =
ranges_to_split_
.front();
29
ranges_to_split_
.pop();
30
size_t
size = range.second - range.first;
31
size_t
mid = range.first + size / 2;
32
// Both sides of the range are added to |ranges_to_split_| so they may be
33
// further split if possible.
34
if
(mid - range.first > 1)
ranges_to_split_
.emplace(range.first, mid);
35
if
(range.second - mid > 1)
ranges_to_split_
.emplace(mid, range.second);
36
return
mid;
37
}
38
39
}
// namespace internal
40
}
// namespace v8
v8::base::LockGuard
Definition
mutex.h:192
v8::internal::IndexGenerator::IndexGenerator
IndexGenerator(size_t size)
Definition
index-generator.cc:12
v8::internal::IndexGenerator::lock_
base::Mutex lock_
Definition
index-generator.h:29
v8::internal::IndexGenerator::first_use_
bool first_use_
Definition
index-generator.h:30
v8::internal::IndexGenerator::ranges_to_split_
std::queue< std::pair< size_t, size_t > > ranges_to_split_
Definition
index-generator.h:32
v8::internal::IndexGenerator::GetNext
std::optional< size_t > GetNext()
Definition
index-generator.cc:18
index-generator.h
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8
Definition
api-arguments-inl.h:19
src
heap
index-generator.cc
Generated on Sun Apr 6 2025 21:08:54 for v8 by
1.12.0