authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-24 17:24:44+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-27 05:37:01+01:00
logd4d210fb377fdf34dc29dd1bc54d59dd5b94a75e
treea2bf01fa654726d2eed90dfe4aef167e242597ee
parent2c7d3c8007dcc8e46c91e92e1d2676af87d1fbcc
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Build.WebServer: use Io futex operations instead of std.Thread.Futex


1 files changed, 14 insertions(+), 3 deletions(-)

lib/std/Build/WebServer.zig+14-3
...@@ -24,7 +24,7 @@ time_report_update_times: []i64,...@@ -24,7 +24,7 @@ time_report_update_times: []i64,
2424
25build_status: std.atomic.Value(abi.BuildStatus),25build_status: std.atomic.Value(abi.BuildStatus),
26/// When an event occurs which means WebSocket clients should be sent updates, call `notifyUpdate`26/// When an event occurs which means WebSocket clients should be sent updates, call `notifyUpdate`
27/// to increment this value. Each client thread waits for this increment with `std.Thread.Futex`, so27/// to increment this value. Each client thread waits for this increment with `Io.futexWaitTimeout`, so
28/// `notifyUpdate` will wake those threads. Updates are sent on a short interval regardless, so it28/// `notifyUpdate` will wake those threads. Updates are sent on a short interval regardless, so it
29/// is recommended to only use `notifyUpdate` for changes which the user should see immediately. For29/// is recommended to only use `notifyUpdate` for changes which the user should see immediately. For
30/// instance, we do not call `notifyUpdate` when the number of "unique runs" in the fuzzer changes,30/// instance, we do not call `notifyUpdate` when the number of "unique runs" in the fuzzer changes,
...@@ -46,7 +46,7 @@ pub const base_clock: Io.Clock = .awake;...@@ -46,7 +46,7 @@ pub const base_clock: Io.Clock = .awake;
46/// Thread-safe. Triggers updates to be sent to connected WebSocket clients; see `update_id`.46/// Thread-safe. Triggers updates to be sent to connected WebSocket clients; see `update_id`.
47pub fn notifyUpdate(ws: *WebServer) void {47pub fn notifyUpdate(ws: *WebServer) void {
48 _ = ws.update_id.rmw(.Add, 1, .release);48 _ = ws.update_id.rmw(.Add, 1, .release);
49 std.Thread.Futex.wake(&ws.update_id, 16);49 ws.graph.io.futexWake(u32, &ws.update_id.raw, 16);
50}50}
5151
52pub const Options = struct {52pub const Options = struct {
...@@ -377,7 +377,18 @@ fn serveWebSocket(ws: *WebServer, sock: *http.Server.WebSocket) !noreturn {...@@ -377,7 +377,18 @@ fn serveWebSocket(ws: *WebServer, sock: *http.Server.WebSocket) !noreturn {
377 }377 }
378378
379 prev_time = start_time;379 prev_time = start_time;
380 std.Thread.Futex.timedWait(&ws.update_id, start_update_id, std.time.ns_per_ms * default_update_interval_ms) catch {};380
381 const old_cp = io.swapCancelProtection(.blocked);
382 defer _ = io.swapCancelProtection(old_cp);
383 io.futexWaitTimeout(
384 u32,
385 &ws.update_id.raw,
386 start_update_id,
387 .{ .duration = .{
388 .clock = .awake,
389 .raw = .fromMilliseconds(default_update_interval_ms),
390 } },
391 ) catch |err| switch (err) { error.Canceled => unreachable };
381 }392 }
382}393}
383fn recvWebSocketMessages(ws: *WebServer, sock: *http.Server.WebSocket) void {394fn recvWebSocketMessages(ws: *WebServer, sock: *http.Server.WebSocket) void {