Add cond_wait_with_timeout

This commit is contained in:
gingerBill
2021-10-11 12:55:25 +01:00
parent 49c761dc6d
commit 73cba2cf13
6 changed files with 60 additions and 13 deletions
+10
View File
@@ -2,6 +2,7 @@
//+private
package sync2
import "core:time"
import "core:sys/unix"
_Mutex_State :: enum i32 {
@@ -37,6 +38,15 @@ _cond_wait :: proc(c: ^Cond, m: ^Mutex) {
assert(err == 0)
}
_cond_wait_with_timeout :: proc(c: ^Cond, m: ^Mutex, duration: time.Duration) -> bool {
tv_sec := i64(duration/1e9)
tv_nsec := i64(duration%1e9)
err := unix.pthread_cond_timedwait(&c.impl.pthread_cond, &m.impl.pthread_mutex, &{tv_sec, tv_nsec})
return err == 0
}
_cond_signal :: proc(c: ^Cond) {
err := unix.pthread_cond_signal(&c.impl.pthread_cond)
assert(err == 0)