S390: Use libc_fe* macros in fe* functions.
[glibc.git] / nptl / tst-join3.c
blobfaf7683eaa11fbd42fe97f0b5bd2a9875039abb7
1 /* Copyright (C) 2002-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include <support/check.h>
26 #include <support/timespec.h>
27 #include <support/xthread.h>
28 #include <support/xtime.h>
31 #define CLOCK_USE_TIMEDJOIN (-1)
33 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
36 static void *
37 tf (void *arg)
39 xpthread_mutex_lock (&lock);
40 xpthread_mutex_unlock (&lock);
42 return (void *) 42l;
46 static int
47 do_test_clock (clockid_t clockid)
49 const clockid_t clockid_for_get =
50 (clockid == CLOCK_USE_TIMEDJOIN) ? CLOCK_REALTIME : clockid;
52 xpthread_mutex_lock (&lock);
53 pthread_t th = xpthread_create (NULL, tf, NULL);
55 void *status;
56 struct timespec timeout = timespec_add (xclock_now (clockid_for_get),
57 make_timespec (0, 200000000));
59 int val;
60 if (clockid == CLOCK_USE_TIMEDJOIN)
61 val = pthread_timedjoin_np (th, &status, &timeout);
62 else
63 val = pthread_clockjoin_np (th, &status, clockid, &timeout);
65 TEST_COMPARE (val, ETIMEDOUT);
67 xpthread_mutex_unlock (&lock);
69 while (1)
71 timeout = timespec_add (xclock_now (clockid_for_get),
72 make_timespec (0, 200000000));
74 if (clockid == CLOCK_USE_TIMEDJOIN)
75 val = pthread_timedjoin_np (th, &status, &timeout);
76 else
77 val = pthread_clockjoin_np (th, &status, clockid, &timeout);
78 if (val == 0)
79 break;
81 TEST_COMPARE (val, ETIMEDOUT);
84 if (status != (void *) 42l)
85 FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l);
87 return 0;
90 static int
91 do_test (void)
93 do_test_clock (CLOCK_USE_TIMEDJOIN);
94 do_test_clock (CLOCK_REALTIME);
95 do_test_clock (CLOCK_MONOTONIC);
96 return 0;
99 #include <support/test-driver.c>