From 4ad8bc341328e289744a0cc796043d0dd52bb32d Mon Sep 17 00:00:00 2001 From: Ben Krieger Date: Wed, 31 Dec 2025 16:38:10 -0500 Subject: [PATCH] Make Io.Mutex an extern struct --- lib/std/Io.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/std/Io.zig b/lib/std/Io.zig index c287115db85ed412cccfd31f60805454c24a2373..cf23796db229468258dd82d06fd66c7690abdd83 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -1348,7 +1348,13 @@ pub fn futexWake(io: Io, comptime T: type, ptr: *align(@alignOf(u32)) const T, m return io.vtable.futexWake(io.userdata, @ptrCast(ptr), max_waiters); } -pub const Mutex = struct { +/// Mutex is a synchronization primitive which enforces atomic access to a +/// shared region of code known as the "critical section". +/// +/// Mutex is an extern struct so that it may be used as a field inside another +/// extern struct. Having a guaranteed memory layout including mutexes is +/// important for IPC over shared memory (mmap). +pub const Mutex = extern struct { state: std.atomic.Value(State), pub const init: Mutex = .{ .state = .init(.unlocked) }; -- 2.54.0