1 /* Copyright (C) 2002-2021 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 <https://www.gnu.org/licenses/>. */
28 pthread_rwlockattr_t at
;
31 if (pthread_rwlockattr_init (&at
) != 0)
33 puts ("rwlockattr_init failed");
36 puts ("rwlockattr_init succeeded");
39 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
42 if (pthread_rwlockattr_setkind_np (&at
, TYPE
) != 0)
44 puts ("rwlockattr_setkind failed");
47 puts ("rwlockattr_setkind succeeded");
49 if (pthread_rwlock_init (&r
, &at
) != 0)
51 puts ("rwlock_init failed");
54 puts ("rwlock_init succeeded");
56 if (pthread_rwlockattr_destroy (&at
) != 0)
58 puts ("rwlockattr_destroy failed");
61 puts ("rwlockattr_destroy succeeded");
63 if (pthread_rwlock_wrlock (&r
) != 0)
65 puts ("1st rwlock_wrlock failed");
68 puts ("1st rwlock_wrlock succeeded");
70 e
= pthread_rwlock_tryrdlock (&r
);
73 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
78 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
81 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
83 e
= pthread_rwlock_trywrlock (&r
);
86 puts ("rwlock_trywrlock on rwlock with writer succeeded");
91 puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
94 puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
96 if (pthread_rwlock_unlock (&r
) != 0)
98 puts ("1st rwlock_unlock failed");
101 puts ("1st rwlock_unlock succeeded");
103 if (pthread_rwlock_tryrdlock (&r
) != 0)
105 puts ("rwlock_tryrdlock on unlocked rwlock failed");
108 puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
110 e
= pthread_rwlock_trywrlock (&r
);
113 puts ("rwlock_trywrlock on rwlock with reader succeeded");
118 puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
121 puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
123 if (pthread_rwlock_unlock (&r
) != 0)
125 puts ("2nd rwlock_unlock failed");
128 puts ("2nd rwlock_unlock succeeded");
130 if (pthread_rwlock_trywrlock (&r
) != 0)
132 puts ("rwlock_trywrlock on unlocked rwlock failed");
135 puts ("rwlock_trywrlock on unlocked rwlock succeeded");
137 e
= pthread_rwlock_tryrdlock (&r
);
140 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
145 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
148 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
150 if (pthread_rwlock_unlock (&r
) != 0)
152 puts ("3rd rwlock_unlock failed");
155 puts ("3rd rwlock_unlock succeeded");
157 if (pthread_rwlock_destroy (&r
) != 0)
159 puts ("rwlock_destroy failed");
162 puts ("rwlock_destroy succeeded");
167 #define TEST_FUNCTION do_test ()
168 #include "../test-skeleton.c"