| ... | @@ -417,6 +417,25 @@ const Thread = struct { | ... | @@ -417,6 +417,25 @@ const Thread = struct { |
| 417 | else => unreachable, | 417 | else => unreachable, |
| 418 | }; | 418 | }; |
| 419 | }, | 419 | }, |
| | 420 | .dragonfly => { |
| | 421 | var timeout_us: c_int = undefined; |
| | 422 | if (timeout_ns) |ns| { |
| | 423 | timeout_us = std.math.cast(c_int, ns / std.time.ns_per_us) orelse std.math.maxInt(c_int); |
| | 424 | } else { |
| | 425 | timeout_us = 0; |
| | 426 | } |
| | 427 | if (thread) |t| try t.beginSyscall(); |
| | 428 | const rc = std.c.umtx_sleep(@ptrCast(ptr), @bitCast(expect), timeout_us); |
| | 429 | if (thread) |t| t.endSyscall(); |
| | 430 | if (is_debug) switch (std.posix.errno(rc)) { |
| | 431 | .SUCCESS => {}, |
| | 432 | .BUSY => {}, // ptr != expect |
| | 433 | .AGAIN => {}, // maybe timed out, or paged out, or hit 2s kernel refresh |
| | 434 | .INTR => {}, // spurious wake |
| | 435 | .INVAL => unreachable, // invalid timeout |
| | 436 | else => unreachable, |
| | 437 | }; |
| | 438 | }, |
| 420 | else => if (std.Thread.use_pthreads) { | 439 | else => if (std.Thread.use_pthreads) { |
| 421 | // TODO integrate the following function being called with robust cancelation. | 440 | // TODO integrate the following function being called with robust cancelation. |
| 422 | return pthreads_futex.wait(ptr, expect, timeout_ns) catch |err| switch (err) { | 441 | return pthreads_futex.wait(ptr, expect, timeout_ns) catch |err| switch (err) { |
| ... | @@ -510,6 +529,13 @@ const Thread = struct { | ... | @@ -510,6 +529,13 @@ const Thread = struct { |
| 510 | ); | 529 | ); |
| 511 | assert(rc >= 0); | 530 | assert(rc >= 0); |
| 512 | }, | 531 | }, |
| | 532 | .dragonfly => { |
| | 533 | // will generally return 0 unless the address is bad |
| | 534 | _ = std.c.umtx_wakeup( |
| | 535 | @ptrCast(ptr), |
| | 536 | @min(max_waiters, std.math.maxInt(c_int)), |
| | 537 | ); |
| | 538 | }, |
| 513 | else => if (std.Thread.use_pthreads) { | 539 | else => if (std.Thread.use_pthreads) { |
| 514 | return pthreads_futex.wake(ptr, max_waiters); | 540 | return pthreads_futex.wake(ptr, max_waiters); |
| 515 | } else { | 541 | } else { |