time: fix .sleep() with `-gc boehm`
parent
8efea1e1c8
commit
517c1841c1
|
@ -4,6 +4,7 @@
|
||||||
module time
|
module time
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
struct C.tm {
|
struct C.tm {
|
||||||
tm_sec int
|
tm_sec int
|
||||||
|
@ -139,6 +140,14 @@ pub fn wait(duration Duration) {
|
||||||
|
|
||||||
// sleep makes the calling thread sleep for a given duration (in nanoseconds).
|
// sleep makes the calling thread sleep for a given duration (in nanoseconds).
|
||||||
pub fn sleep(duration Duration) {
|
pub fn sleep(duration Duration) {
|
||||||
ts := &C.timespec{duration / second, duration % second}
|
mut req := C.timespec{duration / second, duration % second}
|
||||||
C.nanosleep(ts, C.NULL)
|
rem := C.timespec{}
|
||||||
|
for C.nanosleep(&req, &rem) < 0 {
|
||||||
|
if C.errno == C.EINTR {
|
||||||
|
// Interrupted by a signal handler
|
||||||
|
req = rem
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue