| ... | @@ -66,7 +66,7 @@ pub fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut} | ... | @@ -66,7 +66,7 @@ pub fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut} |
| 66 | pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void { | 66 | pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void { |
| 67 | if (single_threaded) return; | 67 | if (single_threaded) return; |
| 68 | if (num_waiters == 0) return; | 68 | if (num_waiters == 0) return; |
| 69 | | 69 | |
| 70 | return OsFutex.wake(ptr, num_waiters); | 70 | return OsFutex.wake(ptr, num_waiters); |
| 71 | } | 71 | } |
| 72 | | 72 | |
| ... | @@ -83,11 +83,11 @@ else | ... | @@ -83,11 +83,11 @@ else |
| 83 | | 83 | |
| 84 | const UnsupportedFutex = struct { | 84 | const UnsupportedFutex = struct { |
| 85 | fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}!void { | 85 | fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}!void { |
| 86 | return unsupported(.{ptr, expect, timeout}); | 86 | return unsupported(.{ ptr, expect, timeout }); |
| 87 | } | 87 | } |
| 88 | | 88 | |
| 89 | fn wake(ptr: *const Atomic(u32), num_waiters: u32) void { | 89 | fn wake(ptr: *const Atomic(u32), num_waiters: u32) void { |
| 90 | return unsupported(.{ptr, num_waiters}); | 90 | return unsupported(.{ ptr, num_waiters }); |
| 91 | } | 91 | } |
| 92 | | 92 | |
| 93 | fn unsupported(unused: anytype) noreturn { | 93 | fn unsupported(unused: anytype) noreturn { |
| ... | @@ -417,7 +417,6 @@ test "Futex - Signal" { | ... | @@ -417,7 +417,6 @@ test "Futex - Signal" { |
| 417 | fn run(self: *@This(), hit_to: *@This()) !void { | 417 | fn run(self: *@This(), hit_to: *@This()) !void { |
| 418 | var iterations: usize = 4; | 418 | var iterations: usize = 4; |
| 419 | while (iterations > 0) : (iterations -= 1) { | 419 | while (iterations > 0) : (iterations -= 1) { |
| 420 | | | |
| 421 | var value: u32 = undefined; | 420 | var value: u32 = undefined; |
| 422 | while (true) { | 421 | while (true) { |
| 423 | value = self.value.load(.Acquire); | 422 | value = self.value.load(.Acquire); |
| ... | @@ -427,7 +426,7 @@ test "Futex - Signal" { | ... | @@ -427,7 +426,7 @@ test "Futex - Signal" { |
| 427 | | 426 | |
| 428 | try testing.expectEqual(value, self.current + 1); | 427 | try testing.expectEqual(value, self.current + 1); |
| 429 | self.current = value; | 428 | self.current = value; |
| 430 | | 429 | |
| 431 | _ = hit_to.value.fetchAdd(1, .Release); | 430 | _ = hit_to.value.fetchAdd(1, .Release); |
| 432 | Futex.wake(&hit_to.value, 1); | 431 | Futex.wake(&hit_to.value, 1); |
| 433 | } | 432 | } |
| ... | @@ -437,10 +436,10 @@ test "Futex - Signal" { | ... | @@ -437,10 +436,10 @@ test "Futex - Signal" { |
| 437 | var ping = Paddle{}; | 436 | var ping = Paddle{}; |
| 438 | var pong = Paddle{}; | 437 | var pong = Paddle{}; |
| 439 | | 438 | |
| 440 | const t1 = try std.Thread.spawn(.{}, Paddle.run, .{&ping, &pong}); | 439 | const t1 = try std.Thread.spawn(.{}, Paddle.run, .{ &ping, &pong }); |
| 441 | defer t1.join(); | 440 | defer t1.join(); |
| 442 | | 441 | |
| 443 | const t2 = try std.Thread.spawn(.{}, Paddle.run, .{&pong, &ping}); | 442 | const t2 = try std.Thread.spawn(.{}, Paddle.run, .{ &pong, &ping }); |
| 444 | defer t2.join(); | 443 | defer t2.join(); |
| 445 | | 444 | |
| 446 | _ = ping.value.fetchAdd(1, .Release); | 445 | _ = ping.value.fetchAdd(1, .Release); |
| ... | @@ -497,7 +496,7 @@ test "Futex - Broadcast" { | ... | @@ -497,7 +496,7 @@ test "Futex - Broadcast" { |
| 497 | | 496 | |
| 498 | // Try to wait for the threads to start before running runSender(). | 497 | // Try to wait for the threads to start before running runSender(). |
| 499 | // NOTE: not actually needed for correctness. | 498 | // NOTE: not actually needed for correctness. |
| 500 | std.time.sleep(16 * std.time.ns_per_ms); | 499 | std.time.sleep(16 * std.time.ns_per_ms); |
| 501 | try ctx.runSender(); | 500 | try ctx.runSender(); |
| 502 | | 501 | |
| 503 | const notified = ctx.notified.load(.Monotonic); | 502 | const notified = ctx.notified.load(.Monotonic); |
| ... | @@ -551,7 +550,7 @@ test "Futex - Chain" { | ... | @@ -551,7 +550,7 @@ test "Futex - Chain" { |
| 551 | var ctx = Context{}; | 550 | var ctx = Context{}; |
| 552 | for (ctx.threads) |*entry, index| { | 551 | for (ctx.threads) |*entry, index| { |
| 553 | entry.signal = .{}; | 552 | entry.signal = .{}; |
| 554 | entry.thread = try std.Thread.spawn(.{}, Context.run, .{&ctx, index}); | 553 | entry.thread = try std.Thread.spawn(.{}, Context.run, .{ &ctx, index }); |
| 555 | } | 554 | } |
| 556 | | 555 | |
| 557 | ctx.threads[0].signal.notify(); | 556 | ctx.threads[0].signal.notify(); |