mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
Threaded.sleepPosix: fix libc error handling
Confusingly, the POSIX spec for clock_nanosleep() says it returns *positive* error values directly and does not touch `errno`. Not detecting EINTR properly here was breaking the cancellation of threads blocked in this call when linking libc.
This commit is contained in:
parent
9b415761dd
commit
ecb9ddf267
1 changed files with 4 additions and 2 deletions
|
|
@ -10083,10 +10083,12 @@ fn sleepPosix(timeout: Io.Timeout) Io.SleepError!void {
|
|||
var timespec: posix.timespec = timestampToPosix(deadline_nanoseconds);
|
||||
const syscall: Syscall = try .start();
|
||||
while (true) {
|
||||
switch (posix.errno(posix.system.clock_nanosleep(clock_id, .{ .ABSTIME = switch (timeout) {
|
||||
const rc = posix.system.clock_nanosleep(clock_id, .{ .ABSTIME = switch (timeout) {
|
||||
.none, .duration => false,
|
||||
.deadline => true,
|
||||
} }, ×pec, ×pec))) {
|
||||
} }, ×pec, ×pec);
|
||||
// POSIX-standard libc clock_nanosleep() returns *positive* errno values directly
|
||||
switch (if (builtin.link_libc) @as(posix.E, @enumFromInt(rc)) else posix.errno(rc)) {
|
||||
.SUCCESS => {
|
||||
syscall.finish();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue