1 /* Copyright (C) 2002-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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/>. */
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)
33 static pthread_mutex_t lock
= PTHREAD_MUTEX_INITIALIZER
;
39 xpthread_mutex_lock (&lock
);
40 xpthread_mutex_unlock (&lock
);
47 do_test_clock (clockid_t clockid
)
49 const clockid_t clockid_for_get
=
50 (clockid
== CLOCK_USE_TIMEDJOIN
) ? CLOCK_REALTIME
: clockid
;
52 xpthread_mutex_lock (&lock
);
53 pthread_t th
= xpthread_create (NULL
, tf
, NULL
);
56 struct timespec timeout
= timespec_add (xclock_now (clockid_for_get
),
57 make_timespec (0, 200000000));
60 if (clockid
== CLOCK_USE_TIMEDJOIN
)
61 val
= pthread_timedjoin_np (th
, &status
, &timeout
);
63 val
= pthread_clockjoin_np (th
, &status
, clockid
, &timeout
);
65 TEST_COMPARE (val
, ETIMEDOUT
);
67 xpthread_mutex_unlock (&lock
);
71 timeout
= timespec_add (xclock_now (clockid_for_get
),
72 make_timespec (0, 200000000));
74 if (clockid
== CLOCK_USE_TIMEDJOIN
)
75 val
= pthread_timedjoin_np (th
, &status
, &timeout
);
77 val
= pthread_clockjoin_np (th
, &status
, clockid
, &timeout
);
81 TEST_COMPARE (val
, ETIMEDOUT
);
84 if (status
!= (void *) 42l)
85 FAIL_EXIT1 ("return value %p, expected %p\n", status
, (void *) 42l);
93 do_test_clock (CLOCK_USE_TIMEDJOIN
);
94 do_test_clock (CLOCK_REALTIME
);
95 do_test_clock (CLOCK_MONOTONIC
);
99 #include <support/test-driver.c>