]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2010-2015 Free Software Foundation, Inc. |
48b42dde AS |
2 | This file is part of the GNU C Library. |
3 | Contributed by Andreas Schwab <schwab@redhat.com>, 2010. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
48b42dde | 18 | |
48b42dde AS |
19 | #include <errno.h> |
20 | #include <pthread.h> | |
145569dc UD |
21 | #include <semaphore.h> |
22 | #include <stdio.h> | |
48b42dde | 23 | |
145569dc UD |
24 | static pthread_cond_t c = PTHREAD_COND_INITIALIZER; |
25 | static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER; | |
26 | static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER; | |
27 | static pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER; | |
28 | static pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER; | |
29 | static sem_t sem; | |
48b42dde AS |
30 | |
31 | static void * | |
32 | th (void *arg) | |
33 | { | |
145569dc | 34 | long int res = 0; |
48b42dde AS |
35 | int r; |
36 | struct timespec t = { -2, 0 }; | |
37 | ||
38 | r = pthread_mutex_timedlock (&m1, &t); | |
145569dc UD |
39 | if (r != ETIMEDOUT) |
40 | { | |
41 | puts ("pthread_mutex_timedlock did not return ETIMEDOUT"); | |
42 | res = 1; | |
43 | } | |
48b42dde | 44 | r = pthread_rwlock_timedrdlock (&rw1, &t); |
145569dc UD |
45 | if (r != ETIMEDOUT) |
46 | { | |
47 | puts ("pthread_rwlock_timedrdlock did not return ETIMEDOUT"); | |
48 | res = 1; | |
49 | } | |
48b42dde | 50 | r = pthread_rwlock_timedwrlock (&rw2, &t); |
145569dc UD |
51 | if (r != ETIMEDOUT) |
52 | { | |
53 | puts ("pthread_rwlock_timedwrlock did not return ETIMEDOUT"); | |
54 | res = 1; | |
55 | } | |
56 | return (void *) res; | |
48b42dde AS |
57 | } |
58 | ||
145569dc | 59 | static int |
48b42dde AS |
60 | do_test (void) |
61 | { | |
145569dc | 62 | int res = 0; |
48b42dde AS |
63 | int r; |
64 | struct timespec t = { -2, 0 }; | |
65 | pthread_t pth; | |
66 | ||
145569dc UD |
67 | sem_init (&sem, 0, 0); |
68 | r = sem_timedwait (&sem, &t); | |
69 | if (r != -1 || errno != ETIMEDOUT) | |
70 | { | |
71 | puts ("sem_timedwait did not fail with ETIMEDOUT"); | |
72 | res = 1; | |
73 | } | |
74 | ||
48b42dde AS |
75 | pthread_mutex_lock (&m1); |
76 | pthread_rwlock_wrlock (&rw1); | |
77 | pthread_rwlock_rdlock (&rw2); | |
78 | pthread_mutex_lock (&m2); | |
03e87550 UD |
79 | if (pthread_create (&pth, 0, th, 0) != 0) |
80 | { | |
81 | puts ("cannot create thread"); | |
82 | return 1; | |
83 | } | |
48b42dde | 84 | r = pthread_cond_timedwait (&c, &m2, &t); |
145569dc UD |
85 | if (r != ETIMEDOUT) |
86 | { | |
87 | puts ("pthread_cond_timedwait did not return ETIMEDOUT"); | |
88 | res = 1; | |
89 | } | |
90 | void *thres; | |
91 | pthread_join (pth, &thres); | |
92 | return res | (thres != NULL); | |
48b42dde AS |
93 | } |
94 | ||
95 | ||
96 | #define TEST_FUNCTION do_test () | |
97 | #include "../test-skeleton.c" |