1 /* Copyright (C) 2004 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 static pthread_barrier_t b
;
28 static pthread_rwlock_t r
= PTHREAD_RWLOCK_INITIALIZER
;
34 /* Lock the read-write lock. */
35 if (pthread_rwlock_wrlock (&r
) != 0)
37 puts ("tf: cannot lock rwlock");
41 pthread_t mt
= *(pthread_t
*) arg
;
43 pthread_barrier_wait (&b
);
45 /* This call will never return. */
46 pthread_join (mt
, NULL
);
58 if (clock_gettime (CLOCK_REALTIME
, &ts
) != 0)
60 puts ("clock_gettime failed");
64 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
66 puts ("barrier_init failed");
70 pthread_t me
= pthread_self ();
72 if (pthread_create (&th
, NULL
, tf
, &me
) != 0)
74 puts ("create failed");
78 /* Wait until the rwlock is locked. */
79 pthread_barrier_wait (&b
);
83 int e
= pthread_rwlock_timedrdlock (&r
, &ts
);
86 puts ("first rwlock_timedrdlock did not fail");
91 puts ("first rwlock_timedrdlock did not return EINVAL");
95 e
= pthread_rwlock_timedwrlock (&r
, &ts
);
98 puts ("first rwlock_timedwrlock did not fail");
101 else if (e
!= EINVAL
)
103 puts ("first rwlock_timedwrlock did not return EINVAL");
107 ts
.tv_nsec
= 1000000000;
109 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
112 puts ("second rwlock_timedrdlock did not fail");
115 else if (e
!= EINVAL
)
117 puts ("second rwlock_timedrdlock did not return EINVAL");
121 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
124 puts ("second rwlock_timedrdlock did not fail");
127 else if (e
!= EINVAL
)
129 puts ("second rwlock_timedrdlock did not return EINVAL");
133 ts
.tv_nsec
= 0x100001000LL
;
134 if (ts
.tv_nsec
!= 0x100001000LL
)
135 ts
.tv_nsec
= 2000000000;
137 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
140 puts ("third rwlock_timedrdlock did not fail");
143 else if (e
!= EINVAL
)
145 puts ("third rwlock_timedrdlock did not return EINVAL");
149 e
= pthread_rwlock_timedrdlock (&r
, &ts
);
152 puts ("third rwlock_timedrdlock did not fail");
155 else if (e
!= EINVAL
)
157 puts ("third rwlock_timedrdlock did not return EINVAL");
168 #define TEST_FUNCTION do_test ()
169 #include "../test-skeleton.c"