summaryrefslogtreecommitdiff
path: root/lib/thread/futex+linux.myr
blob: c5dbf062d2feb9d39c7f941a0f7ffc32b02f793e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 ftxwakeall : (uaddr : ftxtag# -> int)
;;

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

const ftxwake = {uaddr
	-> (sys.futex((uaddr : int32#), sys.Futexwake | sys.Futexpriv, 1, Zptr, Zptr, 0) : int)
}

const ftxwakeall = {uaddr
	-> (sys.futex((uaddr : int32#), sys.Futexwake | sys.Futexpriv, 0x7fffffff, Zptr, Zptr, 0) : int)
}

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)}
;;