7ff1857560
This is a reland of commit ea9a1f1cbe
Changes since revert:
- Make the state field uintptr-aligned since arm64 faults on
atomic accesses to non-naturally aligned addresses.
Original change's description:
> [shared-struct] Add Atomics.Mutex
>
> This CL adds a moving GC-safe, JS-exposed mutex behind the
> --harmony-struct flag. It uses a ParkingLot-inspired algorithm and
> each mutex manages its own waiter queue.
>
> For more details, please see the design doc: https://docs.google.com/document/d/1QHkmiTF770GKxtoP-VQ1eKF42MpedLUeqiQPfCqus0Y/edit?usp=sharing
>
> Bug: v8:12547
> Change-Id: Ic58f8750d2e14ecd573173d17d5235a136bedef9
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3595460
> Commit-Queue: Shu-yu Guo <syg@chromium.org>
> Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
> Reviewed-by: Adam Klein <adamk@chromium.org>
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#80789}
Bug: v8:12547
Change-Id: I776cbf6ea860dcc6cb0ac51694a9b584b53d255c
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng
Cq-Include-Trybots: luci.v8.try:v8_mac_arm64_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3673354
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80875}
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
// Copyright 2022 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.
|
|
//
|
|
// Flags: --harmony-struct --allow-natives-syntax
|
|
|
|
"use strict";
|
|
|
|
if (this.Worker) {
|
|
|
|
(function TestMutexWorkers() {
|
|
let workerScript =
|
|
`onmessage = function(msg) {
|
|
let mutex = msg.mutex;
|
|
let box = msg.box;
|
|
for (let i = 0; i < 10; i++) {
|
|
Atomics.Mutex.lock(mutex, function() {
|
|
box.counter++;
|
|
});
|
|
}
|
|
postMessage("done");
|
|
};
|
|
postMessage("started");`;
|
|
|
|
let worker1 = new Worker(workerScript, { type: 'string' });
|
|
let worker2 = new Worker(workerScript, { type: 'string' });
|
|
assertEquals("started", worker1.getMessage());
|
|
assertEquals("started", worker2.getMessage());
|
|
|
|
let Box = new SharedStructType(['counter']);
|
|
let box = new Box();
|
|
box.counter = 0;
|
|
let mutex = new Atomics.Mutex();
|
|
let msg = { mutex, box };
|
|
worker1.postMessage(msg);
|
|
worker2.postMessage(msg);
|
|
assertEquals("done", worker1.getMessage());
|
|
assertEquals("done", worker2.getMessage());
|
|
assertEquals(20, box.counter);
|
|
|
|
worker1.terminate();
|
|
worker2.terminate();
|
|
})();
|
|
|
|
}
|