]>
Commit | Line | Data |
---|---|---|
dff8da6b | 1 | /* Copyright (C) 2010-2024 Free Software Foundation, Inc. |
48b42dde | 2 | This file is part of the GNU C Library. |
48b42dde AS |
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/>. */ |
48b42dde | 17 | |
48b42dde AS |
18 | #include <errno.h> |
19 | #include <pthread.h> | |
145569dc UD |
20 | #include <semaphore.h> |
21 | #include <stdio.h> | |
44ac6ee9 MC |
22 | #include <support/check.h> |
23 | #include <support/xthread.h> | |
48b42dde | 24 | |
145569dc UD |
25 | static pthread_cond_t c = PTHREAD_COND_INITIALIZER; |
26 | static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER; | |
27 | static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER; | |
28 | static pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER; | |
29 | static pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER; | |
30 | static sem_t sem; | |
48b42dde AS |
31 | |
32 | static void * | |
33 | th (void *arg) | |
34 | { | |
48b42dde AS |
35 | struct timespec t = { -2, 0 }; |
36 | ||
44ac6ee9 | 37 | TEST_COMPARE (pthread_mutex_timedlock (&m1, &t), ETIMEDOUT); |
9d20e22e MC |
38 | TEST_COMPARE (pthread_mutex_clocklock (&m1, CLOCK_REALTIME, &t), ETIMEDOUT); |
39 | TEST_COMPARE (pthread_mutex_clocklock (&m1, CLOCK_MONOTONIC, &t), ETIMEDOUT); | |
44ac6ee9 MC |
40 | TEST_COMPARE (pthread_rwlock_timedrdlock (&rw1, &t), ETIMEDOUT); |
41 | TEST_COMPARE (pthread_rwlock_timedwrlock (&rw2, &t), ETIMEDOUT); | |
e996fa72 MC |
42 | TEST_COMPARE (pthread_rwlock_clockrdlock (&rw1, CLOCK_REALTIME, &t), |
43 | ETIMEDOUT); | |
44 | TEST_COMPARE (pthread_rwlock_clockwrlock (&rw2, CLOCK_REALTIME, &t), | |
45 | ETIMEDOUT); | |
46 | TEST_COMPARE (pthread_rwlock_clockrdlock (&rw1, CLOCK_MONOTONIC, &t), | |
47 | ETIMEDOUT); | |
48 | TEST_COMPARE (pthread_rwlock_clockwrlock (&rw2, CLOCK_MONOTONIC, &t), | |
49 | ETIMEDOUT); | |
44ac6ee9 | 50 | return NULL; |
48b42dde AS |
51 | } |
52 | ||
145569dc | 53 | static int |
48b42dde AS |
54 | do_test (void) |
55 | { | |
48b42dde | 56 | struct timespec t = { -2, 0 }; |
48b42dde | 57 | |
145569dc | 58 | sem_init (&sem, 0, 0); |
44ac6ee9 MC |
59 | TEST_COMPARE (sem_timedwait (&sem, &t), -1); |
60 | TEST_COMPARE (errno, ETIMEDOUT); | |
61 | ||
62 | xpthread_mutex_lock (&m1); | |
63 | xpthread_rwlock_wrlock (&rw1); | |
64 | xpthread_rwlock_rdlock (&rw2); | |
65 | xpthread_mutex_lock (&m2); | |
66 | pthread_t pth = xpthread_create (0, th, 0); | |
67 | TEST_COMPARE (pthread_cond_timedwait (&c, &m2, &t), ETIMEDOUT); | |
68 | xpthread_join (pth); | |
69 | return 0; | |
48b42dde AS |
70 | } |
71 | ||
44ac6ee9 | 72 | #include <support/test-driver.c> |