mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 04:10:07 +00:00
Add cond_wait_with_timeout
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user