runtime-futex.cc 2.27 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/base/platform/time.h"
8
#include "src/common/globals.h"
9 10
#include "src/execution/arguments-inl.h"
#include "src/execution/futex-emulation.h"
11
#include "src/logging/counters.h"
12
#include "src/numbers/conversions-inl.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, 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
RUNTIME_FUNCTION(Runtime_AtomicsNumAsyncWaitersForTesting) {
  DCHECK_EQ(0, args.length());
  return FutexEmulation::NumAsyncWaitersForTesting(isolate);
}

RUNTIME_FUNCTION(Runtime_AtomicsNumUnresolvedAsyncPromisesForTesting) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0);
  CONVERT_SIZE_ARG_CHECKED(index, 1);
  CHECK(!sta->WasDetached());
  CHECK(sta->GetBuffer()->is_shared());
  CHECK_LT(index, sta->length());
  CHECK_EQ(sta->type(), kExternalInt32Array);

  Handle<JSArrayBuffer> array_buffer = sta->GetBuffer();
  size_t addr = (index << 2) + sta->byte_offset();

  return FutexEmulation::NumUnresolvedAsyncPromisesForTesting(array_buffer,
                                                              addr);
}

61 62 63 64 65 66
RUNTIME_FUNCTION(Runtime_SetAllowAtomicsWait) {
  HandleScope scope(isolate);
  DCHECK_EQ(1, args.length());
  CONVERT_BOOLEAN_ARG_CHECKED(set, 0);

  isolate->set_allow_atomics_wait(set);
67
  return ReadOnlyRoots(isolate).undefined_value();
68
}
69

70 71
}  // namespace internal
}  // namespace v8