1 /* Copyright (C) 2002-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
24 #include <support/check.h>
25 #include <support/timespec.h>
26 #include <support/xthread.h>
27 #include <support/xtime.h>
30 #define CLOCK_USE_TIMEDJOIN (-1)
32 static pthread_mutex_t lock
= PTHREAD_MUTEX_INITIALIZER
;
38 xpthread_mutex_lock (&lock
);
39 xpthread_mutex_unlock (&lock
);
46 do_test_clock (clockid_t clockid
)
48 const clockid_t clockid_for_get
=
49 (clockid
== CLOCK_USE_TIMEDJOIN
) ? CLOCK_REALTIME
: clockid
;
51 xpthread_mutex_lock (&lock
);
52 pthread_t th
= xpthread_create (NULL
, tf
, NULL
);
55 struct timespec timeout
= timespec_add (xclock_now (clockid_for_get
),
56 make_timespec (0, 200000000));
59 if (clockid
== CLOCK_USE_TIMEDJOIN
)
60 val
= pthread_timedjoin_np (th
, &status
, &timeout
);
62 val
= pthread_clockjoin_np (th
, &status
, clockid
, &timeout
);
64 TEST_COMPARE (val
, ETIMEDOUT
);
66 xpthread_mutex_unlock (&lock
);
70 timeout
= timespec_add (xclock_now (clockid_for_get
),
71 make_timespec (0, 200000000));
73 if (clockid
== CLOCK_USE_TIMEDJOIN
)
74 val
= pthread_timedjoin_np (th
, &status
, &timeout
);
76 val
= pthread_clockjoin_np (th
, &status
, clockid
, &timeout
);
80 TEST_COMPARE (val
, ETIMEDOUT
);
83 if (status
!= (void *) 42l)
84 FAIL_EXIT1 ("return value %p, expected %p\n", status
, (void *) 42l);
92 do_test_clock (CLOCK_USE_TIMEDJOIN
);
93 do_test_clock (CLOCK_REALTIME
);
94 do_test_clock (CLOCK_MONOTONIC
);
98 #include <support/test-driver.c>