1 /* Copyright (C) 2002 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 pthread_rwlockattr_t at
;
32 if (pthread_rwlockattr_init (&at
) != 0)
34 puts ("rwlockattr_init failed");
37 puts ("rwlockattr_init succeeded");
40 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
43 if (pthread_rwlockattr_setkind_np (&at
, TYPE
) != 0)
45 puts ("rwlockattr_setkind failed");
48 puts ("rwlockattr_setkind succeeded");
50 if (pthread_rwlock_init (&r
, &at
) != 0)
52 puts ("rwlock_init failed");
55 puts ("rwlock_init succeeded");
57 if (pthread_rwlockattr_destroy (&at
) != 0)
59 puts ("rwlockattr_destroy failed");
62 puts ("rwlockattr_destroy succeeded");
64 if (pthread_rwlock_wrlock (&r
) != 0)
66 puts ("1st rwlock_wrlock failed");
69 puts ("1st rwlock_wrlock succeeded");
71 e
= pthread_rwlock_tryrdlock (&r
);
74 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
79 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
82 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
84 e
= pthread_rwlock_trywrlock (&r
);
87 puts ("rwlock_trywrlock on rwlock with writer succeeded");
92 puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
95 puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
97 if (pthread_rwlock_unlock (&r
) != 0)
99 puts ("1st rwlock_unlock failed");
102 puts ("1st rwlock_unlock succeeded");
104 if (pthread_rwlock_tryrdlock (&r
) != 0)
106 puts ("rwlock_tryrdlock on unlocked rwlock failed");
109 puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
111 e
= pthread_rwlock_trywrlock (&r
);
114 puts ("rwlock_trywrlock on rwlock with reader succeeded");
119 puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
122 puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
124 if (pthread_rwlock_unlock (&r
) != 0)
126 puts ("2nd rwlock_unlock failed");
129 puts ("2nd rwlock_unlock succeeded");
131 if (pthread_rwlock_trywrlock (&r
) != 0)
133 puts ("rwlock_trywrlock on unlocked rwlock failed");
136 puts ("rwlock_trywrlock on unlocked rwlock succeeded");
138 e
= pthread_rwlock_tryrdlock (&r
);
141 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
146 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
149 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
151 if (pthread_rwlock_unlock (&r
) != 0)
153 puts ("3rd rwlock_unlock failed");
156 puts ("3rd rwlock_unlock succeeded");
158 if (pthread_rwlock_destroy (&r
) != 0)
160 puts ("rwlock_destroy failed");
163 puts ("rwlock_destroy succeeded");
168 #define TEST_FUNCTION do_test ()
169 #include "../test-skeleton.c"