Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (46 sloc) 1.104 kb
9a3f5ca Split the futex-y operations out into a header file rather than
Steven Smith authored
1 #ifndef FUTEX_H__
2 #define FUTEX_H__
3
4 static inline unsigned
5 atomic_cmpxchg(volatile unsigned *loc, unsigned old, unsigned new)
6 {
7 unsigned long res;
8 asm ("lock cmpxchg %3, %1\n"
9 : "=a" (res), "=m" (*loc)
10 : "0" (old),
11 "r" (new),
12 "m" (*loc)
13 : "memory");
14 return res;
15 }
16
17 static inline unsigned
18 atomic_xchg(volatile unsigned *loc, unsigned new)
19 {
20 unsigned long res;
21 asm ("xchg %0, %1\n"
22 : "=r" (res),
23 "=m" (*loc)
24 : "m" (*loc),
25 "0" (new)
26 : "memory");
27 return res;
28 }
29
30 static inline int
31 futex(volatile unsigned *slot, int cmd, unsigned val, const struct timespec *ts,
32 int *uaddr, int val2)
33 {
34 return syscall(SYS_futex, slot, cmd, val, ts, uaddr, val2);
35 }
36
37 static inline void
38 futex_wait_while_equal(volatile unsigned *slot, unsigned val)
39 {
40 assert((unsigned long)slot % 4 == 0);
41 if (futex(slot, FUTEX_WAIT, val, NULL, NULL, 0) < 0 && errno != EAGAIN)
42 err(1, "futex_wait");
43 }
44
45 static inline void
46 futex_wake(volatile unsigned *slot)
47 {
48 if (futex(slot, FUTEX_WAKE, 1, NULL, NULL, 0) < 0)
49 err(1, "futex_wake");
50 }
51
52 #endif /* !FUTEX_H__ */
Something went wrong with that request. Please try again.