]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/pthread/tst-join3.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / pthread / tst-join3.c
1 /* Copyright (C) 2002-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
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/>. */
18
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>
29
30
31 #define CLOCK_USE_TIMEDJOIN (-1)
32
33 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
34
35
36 static void *
37 tf (void *arg)
38 {
39 xpthread_mutex_lock (&lock);
40 xpthread_mutex_unlock (&lock);
41
42 return (void *) 42l;
43 }
44
45
46 static int
47 do_test_clock (clockid_t clockid)
48 {
49 const clockid_t clockid_for_get =
50 (clockid == CLOCK_USE_TIMEDJOIN) ? CLOCK_REALTIME : clockid;
51
52 xpthread_mutex_lock (&lock);
53 pthread_t th = xpthread_create (NULL, tf, NULL);
54
55 void *status;
56 struct timespec timeout = timespec_add (xclock_now (clockid_for_get),
57 make_timespec (0, 200000000));
58
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);
64
65 TEST_COMPARE (val, ETIMEDOUT);
66
67 xpthread_mutex_unlock (&lock);
68
69 while (1)
70 {
71 timeout = timespec_add (xclock_now (clockid_for_get),
72 make_timespec (0, 200000000));
73
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;
80
81 TEST_COMPARE (val, ETIMEDOUT);
82 }
83
84 if (status != (void *) 42l)
85 FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l);
86
87 return 0;
88 }
89
90 static int
91 do_test (void)
92 {
93 do_test_clock (CLOCK_USE_TIMEDJOIN);
94 do_test_clock (CLOCK_REALTIME);
95 do_test_clock (CLOCK_MONOTONIC);
96 return 0;
97 }
98
99 #include <support/test-driver.c>