| ... | @@ -1102,6 +1102,33 @@ const Thread = struct { | ... | @@ -1102,6 +1102,33 @@ const Thread = struct { |
| 1102 | else => unreachable, | 1102 | else => unreachable, |
| 1103 | }; | 1103 | }; |
| 1104 | }, | 1104 | }, |
| | 1105 | .serenity => { |
| | 1106 | var tm: std.c.timespec = undefined; |
| | 1107 | var tm_ptr: ?*const std.c.timespec = null; |
| | 1108 | if (timeout_ns) |ns| { |
| | 1109 | tm_ptr = &tm; |
| | 1110 | tm = timestampToPosix(ns); |
| | 1111 | } |
| | 1112 | const syscall: Syscall = if (uncancelable) .{ .thread = null } else try .start(); |
| | 1113 | const rc = std.c.futex( |
| | 1114 | @constCast(ptr), |
| | 1115 | std.c.FUTEX.WAIT | std.c.FUTEX.PRIVATE_FLAG, |
| | 1116 | expect, |
| | 1117 | tm_ptr, |
| | 1118 | null, |
| | 1119 | 0, |
| | 1120 | ); |
| | 1121 | syscall.finish(); |
| | 1122 | if (is_debug) switch (posix.errno(rc)) { |
| | 1123 | .SUCCESS => {}, |
| | 1124 | .AGAIN => {}, // ptr != expect |
| | 1125 | .TIMEDOUT => {}, // timeout |
| | 1126 | .FAULT => unreachable, // ptr was invalid |
| | 1127 | .INVAL => unreachable, // ptr was misaligned |
| | 1128 | .NOMEM => {}, // OOM, treat as spurious wake |
| | 1129 | else => unreachable, |
| | 1130 | }; |
| | 1131 | }, |
| 1105 | else => @compileError("unimplemented: futexWait"), | 1132 | else => @compileError("unimplemented: futexWait"), |
| 1106 | } | 1133 | } |
| 1107 | } | 1134 | } |
| ... | @@ -1167,12 +1194,12 @@ const Thread = struct { | ... | @@ -1167,12 +1194,12 @@ const Thread = struct { |
| 1167 | 0, // there is no timeout struct | 1194 | 0, // there is no timeout struct |
| 1168 | 0, // there is no timeout struct pointer | 1195 | 0, // there is no timeout struct pointer |
| 1169 | ); | 1196 | ); |
| 1170 | switch (posix.errno(rc)) { | 1197 | if (is_debug) switch (posix.errno(rc)) { |
| 1171 | .SUCCESS => {}, | 1198 | .SUCCESS => {}, |
| 1172 | .FAULT => {}, // it's ok if the ptr doesn't point to valid memory | 1199 | .FAULT => {}, // it's ok if the ptr doesn't point to valid memory |
| 1173 | .INVAL => unreachable, // arguments should be correct | 1200 | .INVAL => unreachable, // arguments should be correct |
| 1174 | else => unreachable, // deadlock due to operating system bug | 1201 | else => unreachable, // deadlock due to operating system bug |
| 1175 | } | 1202 | }; |
| 1176 | }, | 1203 | }, |
| 1177 | .openbsd => { | 1204 | .openbsd => { |
| 1178 | const rc = std.c.futex( | 1205 | const rc = std.c.futex( |
| ... | @@ -1191,6 +1218,22 @@ const Thread = struct { | ... | @@ -1191,6 +1218,22 @@ const Thread = struct { |
| 1191 | @min(max_waiters, std.math.maxInt(c_int)), | 1218 | @min(max_waiters, std.math.maxInt(c_int)), |
| 1192 | ); | 1219 | ); |
| 1193 | }, | 1220 | }, |
| | 1221 | .serenity => { |
| | 1222 | const rc = std.c.futex( |
| | 1223 | @constCast(ptr), |
| | 1224 | std.c.FUTEX.WAKE | std.c.FUTEX.PRIVATE_FLAG, |
| | 1225 | max_waiters, |
| | 1226 | null, |
| | 1227 | null, |
| | 1228 | 0, |
| | 1229 | ); |
| | 1230 | if (is_debug) switch (posix.errno(rc)) { |
| | 1231 | .SUCCESS => {}, |
| | 1232 | .FAULT => {}, // it's ok if the ptr doesn't point to valid memory |
| | 1233 | .INVAL => unreachable, // arguments should be correct |
| | 1234 | else => unreachable, |
| | 1235 | }; |
| | 1236 | }, |
| 1194 | else => @compileError("unimplemented: futexWake"), | 1237 | else => @compileError("unimplemented: futexWake"), |
| 1195 | } | 1238 | } |
| 1196 | } | 1239 | } |