1 /* Copyright (C) 2004-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
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 <http://www.gnu.org/licenses/>. */
26 static pthread_barrier_t b
;
27 static pthread_rwlock_t r
= PTHREAD_RWLOCK_INITIALIZER
;
33 /* Lock the read-write lock. */
34 if (pthread_rwlock_wrlock (&r
) != 0)
36 puts ("tf: cannot lock rwlock");
40 pthread_t mt
= *(pthread_t
*) arg
;
42 pthread_barrier_wait (&b
);
44 /* This call will never return. */
45 pthread_join (mt
, NULL
);
57 if (clock_gettime (CLOCK_REALTIME
, &ts
) != 0)
59 puts ("clock_gettime failed");
63 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
65 puts ("barrier_init failed");
69 pthread_t me
= pthread_self ();
71 if (pthread_create (&th
, NULL
, tf
, &me
) != 0)
73 puts ("create failed");
77 /* Wait until the rwlock is locked. */
78 pthread_barrier_wait (&b
);
82 int e
= pthread_rwlock_timedrdlock (&r
, &ts
);
85 puts ("first rwlock_timedrdlock did not fail");
90 puts ("first rwlock_timedrdlock did not return EINVAL");
94 e
= pthread_rwlock_timedwrlock (&r
, &ts
);
97 puts ("first rwlock_timedwrlock did not fail");
100 else if (e
!= EINVAL
)
102 puts ("first rwlock_timedwrlock did not return EINVAL");
106 ts
.tv_nsec
= 1000000000;
108 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
111 puts ("second rwlock_timedrdlock did not fail");
114 else if (e
!= EINVAL
)
116 puts ("second rwlock_timedrdlock did not return EINVAL");
120 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
123 puts ("second rwlock_timedrdlock did not fail");
126 else if (e
!= EINVAL
)
128 puts ("second rwlock_timedrdlock did not return EINVAL");
132 ts
.tv_nsec
= (__typeof (ts
.tv_nsec
)) 0x100001000LL
;
133 if ((__typeof (ts
.tv_nsec
)) 0x100001000LL
!= 0x100001000LL
)
134 ts
.tv_nsec
= 2000000000;
136 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
139 puts ("third rwlock_timedrdlock did not fail");
142 else if (e
!= EINVAL
)
144 puts ("third rwlock_timedrdlock did not return EINVAL");
148 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
151 puts ("third rwlock_timedrdlock did not fail");
154 else if (e
!= EINVAL
)
156 puts ("third rwlock_timedrdlock did not return EINVAL");
167 #define TEST_FUNCTION do_test ()
168 #include "../test-skeleton.c"