| ... | @@ -390,6 +390,33 @@ const Thread = struct { | ... | @@ -390,6 +390,33 @@ const Thread = struct { |
| 390 | else => unreachable, | 390 | else => unreachable, |
| 391 | }; | 391 | }; |
| 392 | }, | 392 | }, |
| | 393 | .openbsd => { |
| | 394 | var tm: std.c.timespec = undefined; |
| | 395 | var tm_ptr: ?*const std.c.timespec = null; |
| | 396 | if (timeout_ns) |ns| { |
| | 397 | tm_ptr = &tm; |
| | 398 | tm = timestampToPosix(ns); |
| | 399 | } |
| | 400 | if (thread) |t| try t.beginSyscall(); |
| | 401 | const rc = std.c.futex( |
| | 402 | ptr, |
| | 403 | std.c.FUTEX.WAIT | std.c.FUTEX.PRIVATE_FLAG, |
| | 404 | @as(c_int, @bitCast(expect)), |
| | 405 | tm_ptr, |
| | 406 | null, // uaddr2 is ignored |
| | 407 | ); |
| | 408 | if (thread) |t| t.endSyscall(); |
| | 409 | if (is_debug) switch (posix.errno(rc)) { |
| | 410 | .SUCCESS => {}, |
| | 411 | .NOSYS => unreachable, // constant op known good value |
| | 412 | .AGAIN => {}, // contents of uaddr != val |
| | 413 | .INVAL => unreachable, // invalid timeout |
| | 414 | .TIMEDOUT => {}, // timeout |
| | 415 | .INTR => {}, // a signal arrived |
| | 416 | .CANCELED => {}, // a signal arrived and SA_RESTART was set |
| | 417 | else => unreachable, |
| | 418 | }; |
| | 419 | }, |
| 393 | else => if (std.Thread.use_pthreads) { | 420 | else => if (std.Thread.use_pthreads) { |
| 394 | // TODO integrate the following function being called with robust cancelation. | 421 | // TODO integrate the following function being called with robust cancelation. |
| 395 | return pthreads_futex.wait(ptr, expect, timeout_ns) catch |err| switch (err) { | 422 | return pthreads_futex.wait(ptr, expect, timeout_ns) catch |err| switch (err) { |
| ... | @@ -473,6 +500,16 @@ const Thread = struct { | ... | @@ -473,6 +500,16 @@ const Thread = struct { |
| 473 | else => unreachable, // deadlock due to operating system bug | 500 | else => unreachable, // deadlock due to operating system bug |
| 474 | } | 501 | } |
| 475 | }, | 502 | }, |
| | 503 | .openbsd => { |
| | 504 | const rc = std.c.futex( |
| | 505 | ptr, |
| | 506 | std.c.FUTEX.WAKE | std.c.FUTEX.PRIVATE_FLAG, |
| | 507 | @min(max_waiters, std.math.maxInt(c_int)), |
| | 508 | null, // timeout is ignored |
| | 509 | null, // uaddr2 is ignored |
| | 510 | ); |
| | 511 | assert(rc >= 0); |
| | 512 | }, |
| 476 | else => if (std.Thread.use_pthreads) { | 513 | else => if (std.Thread.use_pthreads) { |
| 477 | return pthreads_futex.wake(ptr, max_waiters); | 514 | return pthreads_futex.wake(ptr, max_waiters); |
| 478 | } else { | 515 | } else { |