summaryrefslogtreecommitdiff
path: root/lib/thread/condvar+openbsd:6.2.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread/condvar+openbsd:6.2.myr')
-rw-r--r--lib/thread/condvar+openbsd:6.2.myr27
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/thread/condvar+openbsd:6.2.myr b/lib/thread/condvar+openbsd:6.2.myr
index 29dbb35..345a3b1 100644
--- a/lib/thread/condvar+openbsd:6.2.myr
+++ b/lib/thread/condvar+openbsd:6.2.myr
@@ -3,12 +3,13 @@ use sys
use "atomic"
use "common"
+use "futex"
use "mutex"
pkg thread =
type cond = struct
_mtx : mutex#
- _seq : uint32
+ _seq : ftxtag
;;
const mkcond : (mtx : mutex# -> cond)
@@ -22,35 +23,29 @@ const mkcond = {mtx
}
const condwait = {cond
- var seq : uint32
- var mtx
+ var mtx = cond._mtx
+ var seq = xget(&cond._seq)
- mtx = cond._mtx
- seq = cond._seq
mtxunlock(mtx)
+ ftxwait(&cond._seq, seq, -1)
/*
- FIXME?: `futex` can be interrupted but `condwait` should always be done
- in a loop anyway.
- */
- sys.futex(&cond._seq, sys.Futexwait, (seq : int), Zptr, Zptr)
-
- /*
- We need to atomically set the mutex to contended. This allows us to
- pass responsibility for waking up the potential other waiters on to the
- unlocker of the mutex.
+ In the event of a broadcast, we need to atomically set the mutex to
+ contended. This allows us to pass responsibility for waking up the
+ potential other waiters from the requeue operation on to the unlocker
+ of the mutex.
*/
mtxcontended(mtx)
}
const condsignal = {cond : cond#
xadd(&cond._seq, 1)
- sys.futex(&cond._seq, sys.Futexwake, 1, Zptr, Zptr)
+ ftxwake(&cond._seq)
}
const condbroadcast = {cond : cond#
xadd(&cond._seq, 1)
- sys.futex(&cond._seq, sys.Futexrequeue, 1,
+ sys.futex((&cond._seq : uint32#), sys.Futexrequeue, 1,
(0x7fffffff : sys.timespec#),
(&cond._mtx._state : uint32#))
}