summaryrefslogtreecommitdiff
path: root/nptl/tst-join5.c
diff options
context:
space:
mode:
Diffstat (limited to 'nptl/tst-join5.c')
-rw-r--r--nptl/tst-join5.c104
1 files changed, 44 insertions, 60 deletions
diff --git a/nptl/tst-join5.c b/nptl/tst-join5.c
index 50e1863757..2fa178cc90 100644
--- a/nptl/tst-join5.c
+++ b/nptl/tst-join5.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -14,7 +14,7 @@
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <pthread.h>
@@ -23,6 +23,10 @@
#include <time.h>
#include <unistd.h>
+#include <support/check.h>
+#include <support/timespec.h>
+#include <support/xthread.h>
+#include <support/xtime.h>
static void
wait_code (void)
@@ -37,22 +41,37 @@ wait_code (void)
static pthread_barrier_t b;
#endif
+static int
+thread_join (pthread_t thread, void **retval)
+{
+#if defined USE_PTHREAD_TIMEDJOIN_NP
+ const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
+ make_timespec (1000, 0));
+ return pthread_timedjoin_np (thread, retval, &ts);
+#elif defined USE_PTHREAD_CLOCKJOIN_NP_REALTIME
+ const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
+ make_timespec (1000, 0));
+ return pthread_clockjoin_np (thread, retval, CLOCK_REALTIME, &ts);
+#elif defined USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC
+ const struct timespec ts = timespec_add (xclock_now (CLOCK_MONOTONIC),
+ make_timespec (1000, 0));
+ return pthread_clockjoin_np (thread, retval, CLOCK_MONOTONIC, &ts);
+#else
+ return pthread_join (thread, retval);
+#endif
+}
+
static void *
tf1 (void *arg)
{
#ifdef WAIT_IN_CHILD
- int e = pthread_barrier_wait (&b);
- if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
- {
- printf ("%s: barrier_wait failed\n", __func__);
- exit (1);
- }
+ xpthread_barrier_wait (&b);
wait_code ();
#endif
- pthread_join ((pthread_t) arg, NULL);
+ thread_join ((pthread_t) arg, NULL);
exit (42);
}
@@ -62,16 +81,12 @@ static void *
tf2 (void *arg)
{
#ifdef WAIT_IN_CHILD
- int e = pthread_barrier_wait (&b);
- if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
- {
- printf ("%s: barrier_wait failed\n", __func__);
- exit (1);
- }
+ xpthread_barrier_wait (&b);
wait_code ();
#endif
- pthread_join ((pthread_t) arg, NULL);
+
+ thread_join ((pthread_t) arg, NULL);
exit (43);
}
@@ -81,16 +96,12 @@ static int
do_test (void)
{
#ifdef WAIT_IN_CHILD
- if (pthread_barrier_init (&b, NULL, 2) != 0)
- {
- puts ("barrier_init failed");
- return 1;
- }
+ xpthread_barrier_init (&b, NULL, 2);
#endif
pthread_t th;
- int err = pthread_join (pthread_self (), NULL);
+ int err = thread_join (pthread_self (), NULL);
if (err == 0)
{
puts ("1st circular join succeeded");
@@ -102,33 +113,20 @@ do_test (void)
return 1;
}
- if (pthread_create (&th, NULL, tf1, (void *) pthread_self ()) != 0)
- {
- puts ("1st create failed");
- return 1;
- }
+ th = xpthread_create (NULL, tf1, (void *) pthread_self ());
#ifndef WAIT_IN_CHILD
wait_code ();
#endif
- if (pthread_cancel (th) != 0)
- {
- puts ("cannot cancel 1st thread");
- return 1;
- }
+ xpthread_cancel (th);
#ifdef WAIT_IN_CHILD
- int e = pthread_barrier_wait (&b);
- if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
- {
- printf ("%s: barrier_wait failed\n", __func__);
- return 1;
- }
+ xpthread_barrier_wait (&b);
#endif
void *r;
- err = pthread_join (th, &r);
+ err = thread_join (th, &r);
if (err != 0)
{
printf ("cannot join 1st thread: %d\n", err);
@@ -140,7 +138,7 @@ do_test (void)
return 1;
}
- err = pthread_join (pthread_self (), NULL);
+ err = thread_join (pthread_self (), NULL);
if (err == 0)
{
puts ("2nd circular join succeeded");
@@ -152,32 +150,19 @@ do_test (void)
return 1;
}
- if (pthread_create (&th, NULL, tf2, (void *) pthread_self ()) != 0)
- {
- puts ("2nd create failed");
- return 1;
- }
+ th = xpthread_create (NULL, tf2, (void *) pthread_self ());
#ifndef WAIT_IN_CHILD
wait_code ();
#endif
- if (pthread_cancel (th) != 0)
- {
- puts ("cannot cancel 2nd thread");
- return 1;
- }
+ xpthread_cancel (th);
#ifdef WAIT_IN_CHILD
- e = pthread_barrier_wait (&b);
- if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
- {
- printf ("%s: barrier_wait failed\n", __func__);
- return 1;
- }
+ xpthread_barrier_wait (&b);
#endif
- if (pthread_join (th, &r) != 0)
+ if (thread_join (th, &r) != 0)
{
puts ("cannot join 2nd thread");
return 1;
@@ -188,7 +173,7 @@ do_test (void)
return 1;
}
- err = pthread_join (pthread_self (), NULL);
+ err = thread_join (pthread_self (), NULL);
if (err == 0)
{
puts ("3rd circular join succeeded");
@@ -203,5 +188,4 @@ do_test (void)
return 0;
}
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>