Permalink
Browse files

Split the futex-y operations out into a header file rather than

putting them in mempipe_thr, so that they're more easily available in
other tests.
  • Loading branch information...
1 parent 27f19da commit 9a3f5ca6ff8f67e5b5a3b9dcc33ac67ecefe7923 Steven Smith committed Nov 22, 2011
Showing with 53 additions and 48 deletions.
  1. +52 −0 futex.h
  2. +1 −48 mempipe_thr.c
View
52 futex.h
@@ -0,0 +1,52 @@
+#ifndef FUTEX_H__
+#define FUTEX_H__
+
+static inline unsigned
+atomic_cmpxchg(volatile unsigned *loc, unsigned old, unsigned new)
+{
+ unsigned long res;
+ asm ("lock cmpxchg %3, %1\n"
+ : "=a" (res), "=m" (*loc)
+ : "0" (old),
+ "r" (new),
+ "m" (*loc)
+ : "memory");
+ return res;
+}
+
+static inline unsigned
+atomic_xchg(volatile unsigned *loc, unsigned new)
+{
+ unsigned long res;
+ asm ("xchg %0, %1\n"
+ : "=r" (res),
+ "=m" (*loc)
+ : "m" (*loc),
+ "0" (new)
+ : "memory");
+ return res;
+}
+
+static inline int
+futex(volatile unsigned *slot, int cmd, unsigned val, const struct timespec *ts,
+ int *uaddr, int val2)
+{
+ return syscall(SYS_futex, slot, cmd, val, ts, uaddr, val2);
+}
+
+static inline void
+futex_wait_while_equal(volatile unsigned *slot, unsigned val)
+{
+ assert((unsigned long)slot % 4 == 0);
+ if (futex(slot, FUTEX_WAIT, val, NULL, NULL, 0) < 0 && errno != EAGAIN)
+ err(1, "futex_wait");
+}
+
+static inline void
+futex_wake(volatile unsigned *slot)
+{
+ if (futex(slot, FUTEX_WAKE, 1, NULL, NULL, 0) < 0)
+ err(1, "futex_wake");
+}
+
+#endif /* !FUTEX_H__ */
View
@@ -59,6 +59,7 @@
#include "test.h"
#include "xutil.h"
+#include "futex.h"
#define PAGE_SIZE 4096
#define CACHE_LINE_SIZE 64
@@ -85,54 +86,6 @@ static void mymemset(void* buf, int byte, size_t count) {
#define test_name "mempipe_thr"
#endif
-static unsigned
-atomic_cmpxchg(volatile unsigned *loc, unsigned old, unsigned new)
-{
- unsigned long res;
- asm ("lock cmpxchg %3, %1\n"
- : "=a" (res), "=m" (*loc)
- : "0" (old),
- "r" (new),
- "m" (*loc)
- : "memory");
- return res;
-}
-
-static unsigned
-atomic_xchg(volatile unsigned *loc, unsigned new)
-{
- unsigned long res;
- asm ("xchg %0, %1\n"
- : "=r" (res),
- "=m" (*loc)
- : "m" (*loc),
- "0" (new)
- : "memory");
- return res;
-}
-
-static int
-futex(volatile unsigned *slot, int cmd, unsigned val, const struct timespec *ts,
- int *uaddr, int val2)
-{
- return syscall(SYS_futex, slot, cmd, val, ts, uaddr, val2);
-}
-
-static void
-futex_wait_while_equal(volatile unsigned *slot, unsigned val)
-{
- assert((unsigned long)slot % 4 == 0);
- if (futex(slot, FUTEX_WAIT, val, NULL, NULL, 0) < 0 && errno != EAGAIN)
- err(1, "futex_wait");
-}
-
-static void
-futex_wake(volatile unsigned *slot)
-{
- if (futex(slot, FUTEX_WAKE, 1, NULL, NULL, 0) < 0)
- err(1, "futex_wake");
-}
-
struct msg_header {
#define MH_FLAG_READY 1
#define MH_FLAG_STOP 2

0 comments on commit 9a3f5ca

Please sign in to comment.