]>
Commit | Line | Data |
---|---|---|
6d7e8eda | 1 | /* Copyright (C) 2002-2023 Free Software Foundation, Inc. |
76a50749 | 2 | This file is part of the GNU C Library. |
76a50749 UD |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
76a50749 UD |
17 | |
18 | #include <errno.h> | |
19 | #include <pthread.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | #include <sys/time.h> | |
22434b2f MC |
24 | #include <support/check.h> |
25 | #include <support/timespec.h> | |
26 | #include <support/xthread.h> | |
27 | #include <support/xtime.h> | |
76a50749 UD |
28 | |
29 | ||
69ca4b54 MC |
30 | #define CLOCK_USE_TIMEDJOIN (-1) |
31 | ||
76a50749 UD |
32 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; |
33 | ||
34 | ||
35 | static void * | |
36 | tf (void *arg) | |
37 | { | |
22434b2f | 38 | xpthread_mutex_lock (&lock); |
69ca4b54 | 39 | xpthread_mutex_unlock (&lock); |
76a50749 UD |
40 | |
41 | return (void *) 42l; | |
42 | } | |
43 | ||
44 | ||
45 | static int | |
69ca4b54 | 46 | do_test_clock (clockid_t clockid) |
76a50749 | 47 | { |
69ca4b54 MC |
48 | const clockid_t clockid_for_get = |
49 | (clockid == CLOCK_USE_TIMEDJOIN) ? CLOCK_REALTIME : clockid; | |
50 | ||
22434b2f MC |
51 | xpthread_mutex_lock (&lock); |
52 | pthread_t th = xpthread_create (NULL, tf, NULL); | |
76a50749 UD |
53 | |
54 | void *status; | |
69ca4b54 | 55 | struct timespec timeout = timespec_add (xclock_now (clockid_for_get), |
22434b2f | 56 | make_timespec (0, 200000000)); |
76a50749 | 57 | |
69ca4b54 MC |
58 | int val; |
59 | if (clockid == CLOCK_USE_TIMEDJOIN) | |
60 | val = pthread_timedjoin_np (th, &status, &timeout); | |
61 | else | |
62 | val = pthread_clockjoin_np (th, &status, clockid, &timeout); | |
63 | ||
22434b2f MC |
64 | TEST_COMPARE (val, ETIMEDOUT); |
65 | ||
66 | xpthread_mutex_unlock (&lock); | |
76a50749 UD |
67 | |
68 | while (1) | |
69 | { | |
69ca4b54 | 70 | timeout = timespec_add (xclock_now (clockid_for_get), |
22434b2f MC |
71 | make_timespec (0, 200000000)); |
72 | ||
69ca4b54 MC |
73 | if (clockid == CLOCK_USE_TIMEDJOIN) |
74 | val = pthread_timedjoin_np (th, &status, &timeout); | |
75 | else | |
76 | val = pthread_clockjoin_np (th, &status, clockid, &timeout); | |
76a50749 UD |
77 | if (val == 0) |
78 | break; | |
79 | ||
22434b2f | 80 | TEST_COMPARE (val, ETIMEDOUT); |
76a50749 UD |
81 | } |
82 | ||
83 | if (status != (void *) 42l) | |
22434b2f | 84 | FAIL_EXIT1 ("return value %p, expected %p\n", status, (void *) 42l); |
76a50749 UD |
85 | |
86 | return 0; | |
87 | } | |
88 | ||
69ca4b54 MC |
89 | static int |
90 | do_test (void) | |
91 | { | |
92 | do_test_clock (CLOCK_USE_TIMEDJOIN); | |
93 | do_test_clock (CLOCK_REALTIME); | |
94 | do_test_clock (CLOCK_MONOTONIC); | |
95 | return 0; | |
96 | } | |
97 | ||
22434b2f | 98 | #include <support/test-driver.c> |