OLD | NEW |
(Empty) | |
| 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/futex-emulation.h" |
| 6 |
| 7 #include "src/v8.h" |
| 8 |
| 9 #include "src/arguments.h" |
| 10 #include "src/base/platform/time.h" |
| 11 #include "src/globals.h" |
| 12 #include "src/runtime/runtime-utils.h" |
| 13 |
| 14 // Implement Futex API for SharedArrayBuffers as defined in the |
| 15 // SharedArrayBuffer draft spec, found here: |
| 16 // https://github.com/lars-t-hansen/ecmascript_sharedmem |
| 17 |
| 18 namespace v8 { |
| 19 namespace internal { |
| 20 |
| 21 RUNTIME_FUNCTION(Runtime_AtomicsFutexWait) { |
| 22 HandleScope scope(isolate); |
| 23 DCHECK(args.length() == 4); |
| 24 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
| 25 CONVERT_SIZE_ARG_CHECKED(index, 1); |
| 26 CONVERT_INT32_ARG_CHECKED(value, 2); |
| 27 CONVERT_DOUBLE_ARG_CHECKED(timeout, 3); |
| 28 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); |
| 29 RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length())); |
| 30 RUNTIME_ASSERT(sta->type() == kExternalInt32Array); |
| 31 RUNTIME_ASSERT(timeout == V8_INFINITY || !std::isnan(timeout)); |
| 32 |
| 33 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); |
| 34 size_t addr = index << 2; |
| 35 |
| 36 return FutexEmulation::Wait(isolate, array_buffer, addr, value, timeout); |
| 37 } |
| 38 |
| 39 |
| 40 RUNTIME_FUNCTION(Runtime_AtomicsFutexWake) { |
| 41 HandleScope scope(isolate); |
| 42 DCHECK(args.length() == 3); |
| 43 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
| 44 CONVERT_SIZE_ARG_CHECKED(index, 1); |
| 45 CONVERT_INT32_ARG_CHECKED(count, 2); |
| 46 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); |
| 47 RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length())); |
| 48 RUNTIME_ASSERT(sta->type() == kExternalInt32Array); |
| 49 |
| 50 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); |
| 51 size_t addr = index << 2; |
| 52 |
| 53 return FutexEmulation::Wake(isolate, array_buffer, addr, count); |
| 54 } |
| 55 |
| 56 |
| 57 RUNTIME_FUNCTION(Runtime_AtomicsFutexWakeOrRequeue) { |
| 58 HandleScope scope(isolate); |
| 59 DCHECK(args.length() == 5); |
| 60 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
| 61 CONVERT_SIZE_ARG_CHECKED(index1, 1); |
| 62 CONVERT_INT32_ARG_CHECKED(count, 2); |
| 63 CONVERT_INT32_ARG_CHECKED(value, 3); |
| 64 CONVERT_SIZE_ARG_CHECKED(index2, 4); |
| 65 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); |
| 66 RUNTIME_ASSERT(index1 < NumberToSize(isolate, sta->length())); |
| 67 RUNTIME_ASSERT(index2 < NumberToSize(isolate, sta->length())); |
| 68 RUNTIME_ASSERT(sta->type() == kExternalInt32Array); |
| 69 |
| 70 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); |
| 71 size_t addr1 = index1 << 2; |
| 72 size_t addr2 = index2 << 2; |
| 73 |
| 74 return FutexEmulation::WakeOrRequeue(isolate, array_buffer, addr1, count, |
| 75 value, addr2); |
| 76 } |
| 77 |
| 78 |
| 79 RUNTIME_FUNCTION(Runtime_AtomicsFutexNumWaitersForTesting) { |
| 80 HandleScope scope(isolate); |
| 81 DCHECK(args.length() == 2); |
| 82 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
| 83 CONVERT_SIZE_ARG_CHECKED(index, 1); |
| 84 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); |
| 85 RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length())); |
| 86 RUNTIME_ASSERT(sta->type() == kExternalInt32Array); |
| 87 |
| 88 Handle<JSArrayBuffer> array_buffer = sta->GetBuffer(); |
| 89 size_t addr = index << 2; |
| 90 |
| 91 return FutexEmulation::NumWaitersForTesting(isolate, array_buffer, addr); |
| 92 } |
| 93 } |
| 94 } // namespace v8::internal |
OLD | NEW |