1 /* Test pthread_cond_clockwait timeout.
3 Copyright (C) 2019-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
27 #include <support/check.h>
28 #include <support/timespec.h>
29 #include <support/xthread.h>
32 static pthread_mutex_t mut
= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
;
33 static pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
37 do_test_clock (clockid_t clockid
)
40 xpthread_mutex_lock (&mut
);
42 /* Waiting for the condition will fail. But we want the timeout here. */
43 const struct timespec ts_now
= xclock_now (clockid
);
44 const struct timespec ts_timeout
=
45 timespec_add (ts_now
, make_timespec (0, 500000000));
47 /* In theory pthread_cond_clockwait could return zero here due to
48 spurious wakeup. However that can't happen without a signal or an
50 TEST_COMPARE (pthread_cond_clockwait (&cond
, &mut
, clockid
, &ts_timeout
),
53 xpthread_mutex_unlock (&mut
);
61 do_test_clock (CLOCK_MONOTONIC
);
62 do_test_clock (CLOCK_REALTIME
);
66 #include <support/test-driver.c>