xref: /openbsd/regress/sys/kern/futex/futex.h (revision 09467b48)
1 /*	$OpenBSD: futex.h,v 1.2 2018/08/26 06:50:30 visa Exp $ */
2 /*
3  * Copyright (c) 2017 Martin Pieuchot
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 static inline int
19 futex_wake(volatile uint32_t *p, int n, int priv)
20 {
21 	return futex(p, FUTEX_WAKE | priv, n, NULL, NULL);
22 }
23 
24 static inline void
25 futex_wait(volatile uint32_t *p, int val, int priv)
26 {
27 	while (*p != (uint32_t)val)
28 		futex(p, FUTEX_WAIT | priv, val, NULL, NULL);
29 }
30 
31 static inline int
32 futex_twait(volatile uint32_t *p, int val, clockid_t clockid,
33     const struct timespec *timeout, int priv)
34 {
35 	return futex(p, FUTEX_WAIT | priv, val, timeout, NULL);
36 }
37 
38 static inline int
39 futex_requeue(volatile uint32_t *p, int n, int m, volatile uint32_t *q)
40 {
41 	return futex(p, FUTEX_REQUEUE, n, (void *)(long)m, q);
42 }
43