runtime-futex.cc 1.48 KB
Newer Older
binji's avatar
binji committed
1 2 3 4
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "src/runtime/runtime-utils.h"
binji's avatar
binji committed
6

7
#include "src/arguments-inl.h"
binji's avatar
binji committed
8
#include "src/base/platform/time.h"
9
#include "src/conversions-inl.h"
10
#include "src/counters.h"
11
#include "src/futex-emulation.h"
binji's avatar
binji committed
12
#include "src/globals.h"
13
#include "src/objects/heap-object-inl.h"
14
#include "src/objects/js-array-buffer-inl.h"
binji's avatar
binji committed
15 16 17

// Implement Futex API for SharedArrayBuffers as defined in the
// SharedArrayBuffer draft spec, found here:
18
// https://github.com/tc39/ecmascript_sharedmem
binji's avatar
binji committed
19 20 21 22

namespace v8 {
namespace internal {

23
RUNTIME_FUNCTION(Runtime_AtomicsNumWaitersForTesting) {
binji's avatar
binji committed
24
  HandleScope scope(isolate);
25
  DCHECK_EQ(2, args.length());
binji's avatar
binji committed
26 27
  CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0);
  CONVERT_SIZE_ARG_CHECKED(index, 1);
28
  CHECK(!sta->WasDetached());
29
  CHECK(sta->GetBuffer()->is_shared());
30
  CHECK_LT(index, NumberToSize(sta->length()));
31
  CHECK_EQ(sta->type(), kExternalInt32Array);
binji's avatar
binji committed
32 33

  Handle<JSArrayBuffer> array_buffer = sta->GetBuffer();
34
  size_t addr = (index << 2) + sta->byte_offset();
binji's avatar
binji committed
35

36
  return FutexEmulation::NumWaitersForTesting(array_buffer, addr);
binji's avatar
binji committed
37
}
38 39 40 41 42 43 44

RUNTIME_FUNCTION(Runtime_SetAllowAtomicsWait) {
  HandleScope scope(isolate);
  DCHECK_EQ(1, args.length());
  CONVERT_BOOLEAN_ARG_CHECKED(set, 0);

  isolate->set_allow_atomics_wait(set);
45
  return ReadOnlyRoots(isolate).undefined_value();
46
}
47

48 49
}  // namespace internal
}  // namespace v8