9 #include <machine/cpufunc.h>
10 #include <machine/atomic.h>
13 static void *do_child(void *arg
);
14 static void *do_parent(void *arg
);
20 main(int ac
, char **av
)
28 printf("tests umtx hand-off loop\n");
32 for (k
= 0; k
< 10; ++k
) {
33 pthread_create(&td1
, NULL
, do_child
, NULL
);
34 pthread_create(&td2
, NULL
, do_parent
, NULL
);
35 pthread_join(td2
, NULL
);
36 pthread_join(td1
, NULL
);
38 stop_timing(total
, "total");
42 while (wait3(&status
, 0, NULL
) <= 0 || errno
== EINTR
)
50 do_child(void *arg __unused
)
54 umtx_sleep(&mtx
, 0, 0);
55 if (atomic_swap_int(&mtx
, 0) == 2) {
67 do_parent(void *arg __unused
)
72 for (j
= 0; j
< 1000000; ++j
) {
73 atomic_swap_int(&mtx
, 1);
77 umtx_sleep(&mtx
, 1, 0);
80 for (j
= 0; j
< 1000000; ++j
) {
81 atomic_swap_int(&mtx
, 1);
84 umtx_sleep(&mtx
, 1, 0);
86 stop_timing(j
, "mtx1");
87 atomic_add_long(&total
, j
* 2);
89 atomic_swap_int(&mtx
, 2);
92 umtx_sleep(&mtx
, 2, 0);