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/>. */
27 pthread_rwlockattr_t at
;
30 if (pthread_rwlockattr_init (&at
) != 0)
32 puts ("rwlockattr_init failed");
35 puts ("rwlockattr_init succeeded");
38 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
41 if (pthread_rwlockattr_setkind_np (&at
, TYPE
) != 0)
43 puts ("rwlockattr_setkind failed");
46 puts ("rwlockattr_setkind succeeded");
48 if (pthread_rwlock_init (&r
, &at
) != 0)
50 puts ("rwlock_init failed");
53 puts ("rwlock_init succeeded");
55 if (pthread_rwlockattr_destroy (&at
) != 0)
57 puts ("rwlockattr_destroy failed");
60 puts ("rwlockattr_destroy succeeded");
62 if (pthread_rwlock_wrlock (&r
) != 0)
64 puts ("1st rwlock_wrlock failed");
67 puts ("1st rwlock_wrlock succeeded");
69 e
= pthread_rwlock_tryrdlock (&r
);
72 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
77 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
80 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
82 e
= pthread_rwlock_trywrlock (&r
);
85 puts ("rwlock_trywrlock on rwlock with writer succeeded");
90 puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
93 puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
95 if (pthread_rwlock_unlock (&r
) != 0)
97 puts ("1st rwlock_unlock failed");
100 puts ("1st rwlock_unlock succeeded");
102 if (pthread_rwlock_tryrdlock (&r
) != 0)
104 puts ("rwlock_tryrdlock on unlocked rwlock failed");
107 puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
109 e
= pthread_rwlock_trywrlock (&r
);
112 puts ("rwlock_trywrlock on rwlock with reader succeeded");
117 puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
120 puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
122 if (pthread_rwlock_unlock (&r
) != 0)
124 puts ("2nd rwlock_unlock failed");
127 puts ("2nd rwlock_unlock succeeded");
129 if (pthread_rwlock_trywrlock (&r
) != 0)
131 puts ("rwlock_trywrlock on unlocked rwlock failed");
134 puts ("rwlock_trywrlock on unlocked rwlock succeeded");
136 e
= pthread_rwlock_tryrdlock (&r
);
139 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
144 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
147 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
149 if (pthread_rwlock_unlock (&r
) != 0)
151 puts ("3rd rwlock_unlock failed");
154 puts ("3rd rwlock_unlock succeeded");
156 if (pthread_rwlock_destroy (&r
) != 0)
158 puts ("rwlock_destroy failed");
161 puts ("rwlock_destroy succeeded");
166 #define TEST_FUNCTION do_test ()
167 #include "../test-skeleton.c"