From 517c1841c1efca3c05a7e17bf334ad656ff2cd79 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 20 Mar 2021 16:16:11 +0200 Subject: [PATCH] time: fix .sleep() with `-gc boehm` --- vlib/time/time_nix.c.v | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/vlib/time/time_nix.c.v b/vlib/time/time_nix.c.v index 79f06c884c..1179519eb7 100644 --- a/vlib/time/time_nix.c.v +++ b/vlib/time/time_nix.c.v @@ -4,6 +4,7 @@ module time #include +#include struct C.tm { tm_sec int @@ -139,6 +140,14 @@ pub fn wait(duration Duration) { // sleep makes the calling thread sleep for a given duration (in nanoseconds). pub fn sleep(duration Duration) { - ts := &C.timespec{duration / second, duration % second} - C.nanosleep(ts, C.NULL) + mut req := C.timespec{duration / second, duration % second} + rem := C.timespec{} + for C.nanosleep(&req, &rem) < 0 { + if C.errno == C.EINTR { + // Interrupted by a signal handler + req = rem + } else { + break + } + } }