malloc: Fix transposed arguments in sysmalloc_mmap_fallback call
[glibc.git] / nptl / tst-rwlock2.c
blob0ab6e9b824e44ff698de384d8dd6851a4adf0354
1 /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <pthread.h>
20 #include <stdio.h>
23 static int
24 do_test (void)
26 pthread_rwlock_t r;
27 pthread_rwlockattr_t at;
28 int e;
30 if (pthread_rwlockattr_init (&at) != 0)
32 puts ("rwlockattr_init failed");
33 return 1;
35 puts ("rwlockattr_init succeeded");
37 #ifndef TYPE
38 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
39 #endif
41 if (pthread_rwlockattr_setkind_np (&at, TYPE) != 0)
43 puts ("rwlockattr_setkind failed");
44 return 1;
46 puts ("rwlockattr_setkind succeeded");
48 if (pthread_rwlock_init (&r, &at) != 0)
50 puts ("rwlock_init failed");
51 return 1;
53 puts ("rwlock_init succeeded");
55 if (pthread_rwlockattr_destroy (&at) != 0)
57 puts ("rwlockattr_destroy failed");
58 return 1;
60 puts ("rwlockattr_destroy succeeded");
62 if (pthread_rwlock_wrlock (&r) != 0)
64 puts ("1st rwlock_wrlock failed");
65 return 1;
67 puts ("1st rwlock_wrlock succeeded");
69 e = pthread_rwlock_tryrdlock (&r);
70 if (e == 0)
72 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
73 return 1;
75 if (e != EBUSY)
77 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
78 return 1;
80 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
82 e = pthread_rwlock_trywrlock (&r);
83 if (e == 0)
85 puts ("rwlock_trywrlock on rwlock with writer succeeded");
86 return 1;
88 if (e != EBUSY)
90 puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
91 return 1;
93 puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
95 if (pthread_rwlock_unlock (&r) != 0)
97 puts ("1st rwlock_unlock failed");
98 return 1;
100 puts ("1st rwlock_unlock succeeded");
102 if (pthread_rwlock_tryrdlock (&r) != 0)
104 puts ("rwlock_tryrdlock on unlocked rwlock failed");
105 return 1;
107 puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
109 e = pthread_rwlock_trywrlock (&r);
110 if (e == 0)
112 puts ("rwlock_trywrlock on rwlock with reader succeeded");
113 return 1;
115 if (e != EBUSY)
117 puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
118 return 1;
120 puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
122 if (pthread_rwlock_unlock (&r) != 0)
124 puts ("2nd rwlock_unlock failed");
125 return 1;
127 puts ("2nd rwlock_unlock succeeded");
129 if (pthread_rwlock_trywrlock (&r) != 0)
131 puts ("rwlock_trywrlock on unlocked rwlock failed");
132 return 1;
134 puts ("rwlock_trywrlock on unlocked rwlock succeeded");
136 e = pthread_rwlock_tryrdlock (&r);
137 if (e == 0)
139 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
140 return 1;
142 if (e != EBUSY)
144 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
145 return 1;
147 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
149 if (pthread_rwlock_unlock (&r) != 0)
151 puts ("3rd rwlock_unlock failed");
152 return 1;
154 puts ("3rd rwlock_unlock succeeded");
156 if (pthread_rwlock_destroy (&r) != 0)
158 puts ("rwlock_destroy failed");
159 return 1;
161 puts ("rwlock_destroy succeeded");
163 return 0;
166 #define TEST_FUNCTION do_test ()
167 #include "../test-skeleton.c"