1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sync: add semaphores (#5831)

This commit is contained in:
Uwe Krüger
2020-07-15 10:22:33 +02:00
committed by GitHub
parent 6a260ad974
commit 8df6e59678
7 changed files with 253 additions and 16 deletions

View File

@@ -35,6 +35,7 @@ type time_t voidptr
// in most systems, these are __quad_t, which is an i64
struct C.timespec {
mut:
tv_sec i64
tv_nsec i64
}
@@ -78,3 +79,27 @@ pub struct C.timeval {
tv_sec u64
tv_usec u64
}
// return absolute timespec for now()+d
pub fn (d Duration) timespec() C.timespec {
mut ts := C.timespec{}
C.clock_gettime(C.CLOCK_REALTIME, &ts)
d_sec := d / second
d_nsec := d % second
ts.tv_sec += d_sec
ts.tv_nsec += d_nsec
if ts.tv_nsec > second {
ts.tv_nsec -= second
ts.tv_sec++
}
return ts
}
// return timespec of 1970/1/1
pub fn zero_timespec() C.timespec {
ts := C.timespec{
tv_sec: 0
tv_nsec: 0
}
return ts
}