v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
runtime-futex.cc
Go to the documentation of this file.
1// Copyright 2015 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
9
10// Implement Futex API for SharedArrayBuffers as defined in the
11// SharedArrayBuffer draft spec, found here:
12// https://github.com/tc39/ecmascript_sharedmem
13
14namespace v8 {
15namespace internal {
16
17RUNTIME_FUNCTION(Runtime_AtomicsNumWaitersForTesting) {
18 HandleScope scope(isolate);
19 DCHECK_EQ(2, args.length());
21 size_t index = NumberToSize(args[1]);
22 CHECK(!sta->WasDetached());
23 CHECK(sta->GetBuffer()->is_shared());
24 CHECK_LT(index, sta->GetLength());
25 CHECK_EQ(sta->type(), kExternalInt32Array);
26
27 DirectHandle<JSArrayBuffer> array_buffer = sta->GetBuffer();
28 size_t addr = (index << 2) + sta->byte_offset();
29
30 return Smi::FromInt(
31 FutexEmulation::NumWaitersForTesting(*array_buffer, addr));
32}
33
34RUNTIME_FUNCTION(Runtime_AtomicsNumUnresolvedAsyncPromisesForTesting) {
35 HandleScope scope(isolate);
36 DCHECK_EQ(2, args.length());
38 size_t index = NumberToSize(args[1]);
39 CHECK(!sta->WasDetached());
40 CHECK(sta->GetBuffer()->is_shared());
41 CHECK_LT(index, sta->GetLength());
42 CHECK_EQ(sta->type(), kExternalInt32Array);
43
44 DirectHandle<JSArrayBuffer> array_buffer = sta->GetBuffer();
45 size_t addr = (index << 2) + sta->byte_offset();
46
48 *array_buffer, addr));
49}
50
51RUNTIME_FUNCTION(Runtime_SetAllowAtomicsWait) {
52 HandleScope scope(isolate);
53 DCHECK_EQ(1, args.length());
54 bool set = Cast<Boolean>(args[0])->ToBool(isolate);
55
56 isolate->set_allow_atomics_wait(set);
57 return ReadOnlyRoots(isolate).undefined_value();
58}
59
60} // namespace internal
61} // namespace v8
static int NumUnresolvedAsyncPromisesForTesting(Tagged< JSArrayBuffer > array_buffer, size_t addr)
static int NumWaitersForTesting(Tagged< JSArrayBuffer > array_buffer, size_t addr)
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
#define RUNTIME_FUNCTION(Name)
Definition arguments.h:162
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
@ kExternalInt32Array
Definition globals.h:2457
size_t NumberToSize(Tagged< Object > number)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK(condition)
Definition logging.h:124
#define CHECK_LT(lhs, rhs)
#define CHECK_EQ(lhs, rhs)
#define DCHECK_EQ(v1, v2)
Definition logging.h:485