shithub: mc

ref: 974475bcfe52a488d9f5e83e474b6ca3670d5f6a
dir: /lib/thread/futex+openbsd:6.2.myr/

View raw version
use sys

use "atomic"
use "common"

pkg thread =
	type ftxtag = uint32
	impl atomic ftxtag

	const ftxwait : (uaddr : ftxtag#, val : ftxtag, timeout : sys.timespec# -> int)
	const ftxwake : (uaddr : ftxtag# -> int)
;;

const ftxwait = {uaddr, val, timeout
	-> sys.futex((uaddr : uint32#), sys.Futexwait, (val : int), timeout, Zptr)
}

const ftxwake = {uaddr
	-> sys.futex((uaddr : uint32#), sys.Futexwake, 1, Zptr, Zptr)
}

impl atomic ftxtag =
	xget = {p; -> (xget32((p : uint32#)) : ftxtag)}
	xset = {p, v; xset32((p : uint32#), (v : uint32))}
	xadd = {p, v; -> (xadd32((p : uint32#), (v : uint32)) : ftxtag)}
	xcas = {p, old, new; -> (xcas32((p : uint32#), (old : uint32), (new : uint32)) : ftxtag)}
	xchg = {p, v; -> (xchg32((p : uint32#), (v : uint32)) : ftxtag)}
;;