* sysdeps/unix/sysv/linux/sys/timerfd.h: New file.
[glibc.git] / nptl / tst-rwlock14.c
blob00e1becbfaeb59e3010dbcf125cc36638dafe2b1
1 /* Copyright (C) 2004, 2007 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
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <time.h>
27 static pthread_barrier_t b;
28 static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER;
31 static void *
32 tf (void *arg)
34 /* Lock the read-write lock. */
35 if (pthread_rwlock_wrlock (&r) != 0)
37 puts ("tf: cannot lock rwlock");
38 exit (EXIT_FAILURE);
41 pthread_t mt = *(pthread_t *) arg;
43 pthread_barrier_wait (&b);
45 /* This call will never return. */
46 pthread_join (mt, NULL);
48 return NULL;
52 static int
53 do_test (void)
55 int result = 0;
56 struct timespec ts;
58 if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
60 puts ("clock_gettime failed");
61 return 1;
64 if (pthread_barrier_init (&b, NULL, 2) != 0)
66 puts ("barrier_init failed");
67 return 1;
70 pthread_t me = pthread_self ();
71 pthread_t th;
72 if (pthread_create (&th, NULL, tf, &me) != 0)
74 puts ("create failed");
75 return 1;
78 /* Wait until the rwlock is locked. */
79 pthread_barrier_wait (&b);
81 ts.tv_nsec = -1;
83 int e = pthread_rwlock_timedrdlock (&r, &ts);
84 if (e == 0)
86 puts ("first rwlock_timedrdlock did not fail");
87 result = 1;
89 else if (e != EINVAL)
91 puts ("first rwlock_timedrdlock did not return EINVAL");
92 result = 1;
95 e = pthread_rwlock_timedwrlock (&r, &ts);
96 if (e == 0)
98 puts ("first rwlock_timedwrlock did not fail");
99 result = 1;
101 else if (e != EINVAL)
103 puts ("first rwlock_timedwrlock did not return EINVAL");
104 result = 1;
107 ts.tv_nsec = 1000000000;
109 e = pthread_rwlock_timedrdlock (&r, &ts);
110 if (e == 0)
112 puts ("second rwlock_timedrdlock did not fail");
113 result = 1;
115 else if (e != EINVAL)
117 puts ("second rwlock_timedrdlock did not return EINVAL");
118 result = 1;
121 e = pthread_rwlock_timedrdlock (&r, &ts);
122 if (e == 0)
124 puts ("second rwlock_timedrdlock did not fail");
125 result = 1;
127 else if (e != EINVAL)
129 puts ("second rwlock_timedrdlock did not return EINVAL");
130 result = 1;
133 ts.tv_nsec = (__typeof (ts.tv_nsec)) 0x100001000LL;
134 if ((__typeof (ts.tv_nsec)) 0x100001000LL != 0x100001000LL)
135 ts.tv_nsec = 2000000000;
137 e = pthread_rwlock_timedrdlock (&r, &ts);
138 if (e == 0)
140 puts ("third rwlock_timedrdlock did not fail");
141 result = 1;
143 else if (e != EINVAL)
145 puts ("third rwlock_timedrdlock did not return EINVAL");
146 result = 1;
149 e = pthread_rwlock_timedrdlock (&r, &ts);
150 if (e == 0)
152 puts ("third rwlock_timedrdlock did not fail");
153 result = 1;
155 else if (e != EINVAL)
157 puts ("third rwlock_timedrdlock did not return EINVAL");
158 result = 1;
161 if (result == 0)
162 puts ("no bugs");
164 return result;
168 #define TEST_FUNCTION do_test ()
169 #include "../test-skeleton.c"