Add issubnormal.
[glibc.git] / nptl / tst-rwlock2.c
blob2b1222e8ee517b2bff686cececc29ca6ec75b786
1 /* Copyright (C) 2002-2016 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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/>. */
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdio.h>
24 static int
25 do_test (void)
27 pthread_rwlock_t r;
28 pthread_rwlockattr_t at;
29 int e;
31 if (pthread_rwlockattr_init (&at) != 0)
33 puts ("rwlockattr_init failed");
34 return 1;
36 puts ("rwlockattr_init succeeded");
38 #ifndef TYPE
39 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
40 #endif
42 if (pthread_rwlockattr_setkind_np (&at, TYPE) != 0)
44 puts ("rwlockattr_setkind failed");
45 return 1;
47 puts ("rwlockattr_setkind succeeded");
49 if (pthread_rwlock_init (&r, &at) != 0)
51 puts ("rwlock_init failed");
52 return 1;
54 puts ("rwlock_init succeeded");
56 if (pthread_rwlockattr_destroy (&at) != 0)
58 puts ("rwlockattr_destroy failed");
59 return 1;
61 puts ("rwlockattr_destroy succeeded");
63 if (pthread_rwlock_wrlock (&r) != 0)
65 puts ("1st rwlock_wrlock failed");
66 return 1;
68 puts ("1st rwlock_wrlock succeeded");
70 e = pthread_rwlock_tryrdlock (&r);
71 if (e == 0)
73 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
74 return 1;
76 if (e != EBUSY)
78 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
79 return 1;
81 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
83 e = pthread_rwlock_trywrlock (&r);
84 if (e == 0)
86 puts ("rwlock_trywrlock on rwlock with writer succeeded");
87 return 1;
89 if (e != EBUSY)
91 puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
92 return 1;
94 puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
96 if (pthread_rwlock_unlock (&r) != 0)
98 puts ("1st rwlock_unlock failed");
99 return 1;
101 puts ("1st rwlock_unlock succeeded");
103 if (pthread_rwlock_tryrdlock (&r) != 0)
105 puts ("rwlock_tryrdlock on unlocked rwlock failed");
106 return 1;
108 puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
110 e = pthread_rwlock_trywrlock (&r);
111 if (e == 0)
113 puts ("rwlock_trywrlock on rwlock with reader succeeded");
114 return 1;
116 if (e != EBUSY)
118 puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
119 return 1;
121 puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
123 if (pthread_rwlock_unlock (&r) != 0)
125 puts ("2nd rwlock_unlock failed");
126 return 1;
128 puts ("2nd rwlock_unlock succeeded");
130 if (pthread_rwlock_trywrlock (&r) != 0)
132 puts ("rwlock_trywrlock on unlocked rwlock failed");
133 return 1;
135 puts ("rwlock_trywrlock on unlocked rwlock succeeded");
137 e = pthread_rwlock_tryrdlock (&r);
138 if (e == 0)
140 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
141 return 1;
143 if (e != EBUSY)
145 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
146 return 1;
148 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
150 if (pthread_rwlock_unlock (&r) != 0)
152 puts ("3rd rwlock_unlock failed");
153 return 1;
155 puts ("3rd rwlock_unlock succeeded");
157 if (pthread_rwlock_destroy (&r) != 0)
159 puts ("rwlock_destroy failed");
160 return 1;
162 puts ("rwlock_destroy succeeded");
164 return 0;
167 #define TEST_FUNCTION do_test ()
168 #include "../test-skeleton.c"