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
5#include "src/runtime/runtime-utils.h"
6
7#include "src/arguments-inl.h"
8#include "src/base/platform/time.h"
9#include "src/conversions-inl.h"
10#include "src/counters.h"
11#include "src/futex-emulation.h"
12#include "src/globals.h"
13#include "src/objects/heap-object-inl.h"
14#include "src/objects/js-array-buffer-inl.h"
15
16// Implement Futex API for SharedArrayBuffers as defined in the
17// SharedArrayBuffer draft spec, found here:
18// https://github.com/tc39/ecmascript_sharedmem
19
20namespace v8 {
21namespace internal {
22
23RUNTIME_FUNCTION(Runtime_AtomicsNumWaitersForTesting) {
24 HandleScope scope(isolate);
25 DCHECK_EQ(2, args.length());
26 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0);
27 CONVERT_SIZE_ARG_CHECKED(index, 1);
28 CHECK(!sta->WasDetached());
29 CHECK(sta->GetBuffer()->is_shared());
30 CHECK_LT(index, sta->length());
31 CHECK_EQ(sta->type(), kExternalInt32Array);
32
33 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer();
34 size_t addr = (index << 2) + sta->byte_offset();
35
36 return FutexEmulation::NumWaitersForTesting(array_buffer, addr);
37}
38
39RUNTIME_FUNCTION(Runtime_SetAllowAtomicsWait) {
40 HandleScope scope(isolate);
41 DCHECK_EQ(1, args.length());
42 CONVERT_BOOLEAN_ARG_CHECKED(set, 0);
43
44 isolate->set_allow_atomics_wait(set);
45 return ReadOnlyRoots(isolate).undefined_value();
46}
47
48} // namespace internal
49} // namespace v8
50