From e65912f8b2a6fa966b1ba45360070cf9f25568b4 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Fri, 28 Oct 2016 18:43:57 +0200 Subject: rework most tests to work as standalone package --- test/nptl/tst-sem11.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'test/nptl/tst-sem11.c') diff --git a/test/nptl/tst-sem11.c b/test/nptl/tst-sem11.c index 6633ddd..a9c616c 100644 --- a/test/nptl/tst-sem11.c +++ b/test/nptl/tst-sem11.c @@ -2,7 +2,14 @@ #include #include #include -#include + +//from internaltypes.h +struct new_sem +{ + unsigned int value; + int private; + unsigned long int nwaiters; +}; #ifndef SEM_WAIT # define SEM_WAIT(s) sem_wait (s) @@ -23,23 +30,28 @@ main (void) { int tries = 5; pthread_t th; - sem_t s; + union + { + sem_t s; + struct new_sem ns; + } u; again: - if (sem_init (&s, 0, 0) != 0) + if (sem_init (&u.s, 0, 0) != 0) { puts ("sem_init failed"); return 1; } - - struct new_sem *is = (struct new_sem *) &s; - - if (is->nwaiters != 0) +#if __HAVE_64B_ATOMICS + if ((u.ns.data >> SEM_NWAITERS_SHIFT) != 0) +#else + if (u.ns.nwaiters != 0) +#endif { puts ("nwaiters not initialized"); return 1; } - if (pthread_create (&th, NULL, tf, &s) != 0) + if (pthread_create (&th, NULL, tf, &u.s) != 0) { puts ("pthread_create failed"); return 1; @@ -62,11 +74,15 @@ main (void) if (r != PTHREAD_CANCELED && --tries > 0) { /* Maybe we get the scheduling right the next time. */ - sem_destroy (&s); + sem_destroy (&u.s); goto again; } - if (is->nwaiters != 0) +#if __HAVE_64B_ATOMICS + if ((u.ns.data >> SEM_NWAITERS_SHIFT) != 0) +#else + if (u.ns.nwaiters != 0) +#endif { puts ("nwaiters not reset"); return 1; -- cgit v1.2.3