cdefs.h: fix "__clang_major" typo
[glibc.git] / sysdeps / pthread / tst-join14.c
bloba894d3b4a1559922ec019b39b271e0911f435c5b
1 /* pthread_timedjoin_np, pthread_clockjoin_np NULL timeout test.
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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)
34 static void *
35 tf (void *arg)
37 struct timespec ts = make_timespec(0, 100000);
38 nanosleep(&ts, NULL);
40 return (void *) 42l;
44 /* Check that pthread_timedjoin_np and pthread_clockjoin_np wait "forever" if
45 * passed a timeout parameter of NULL. We can't actually wait forever, but we
46 * can be sure that we did at least wait for some time by checking the exit
47 * status of the thread. */
48 static int
49 do_test_clock (clockid_t clockid)
51 pthread_t th = xpthread_create (NULL, tf, NULL);
53 void *status;
54 int val = (clockid == CLOCK_USE_TIMEDJOIN)
55 ? pthread_timedjoin_np (th, &status, NULL)
56 : pthread_clockjoin_np (th, &status, clockid, NULL);
57 TEST_COMPARE (val, 0);
59 if (status != (void *) 42l)
60 FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l);
62 return 0;
65 static int
66 do_test (void)
68 do_test_clock (CLOCK_USE_TIMEDJOIN);
69 do_test_clock (CLOCK_REALTIME);
70 do_test_clock (CLOCK_MONOTONIC);
71 return 0;
74 #include <support/test-driver.c>