* sysdeps/mach/i386/machine-lock.h (__spin_unlock, __spin_try_lock):
[glibc.git] / nptl / tst-rwlock2.c
blob2d2e8e4a3e71b602286ce71df6cc6a26391766df
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
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <stdio.h>
25 static int
26 do_test (void)
28 pthread_rwlock_t r;
29 pthread_rwlockattr_t at;
30 int e;
32 if (pthread_rwlockattr_init (&at) != 0)
34 puts ("rwlockattr_init failed");
35 return 1;
37 puts ("rwlockattr_init succeeded");
39 #ifndef TYPE
40 # define TYPE PTHREAD_RWLOCK_PREFER_READER_NP
41 #endif
43 if (pthread_rwlockattr_setkind_np (&at, TYPE) != 0)
45 puts ("rwlockattr_setkind failed");
46 return 1;
48 puts ("rwlockattr_setkind succeeded");
50 if (pthread_rwlock_init (&r, &at) != 0)
52 puts ("rwlock_init failed");
53 return 1;
55 puts ("rwlock_init succeeded");
57 if (pthread_rwlockattr_destroy (&at) != 0)
59 puts ("rwlockattr_destroy failed");
60 return 1;
62 puts ("rwlockattr_destroy succeeded");
64 if (pthread_rwlock_wrlock (&r) != 0)
66 puts ("1st rwlock_wrlock failed");
67 return 1;
69 puts ("1st rwlock_wrlock succeeded");
71 e = pthread_rwlock_tryrdlock (&r);
72 if (e == 0)
74 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
75 return 1;
77 if (e != EBUSY)
79 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
80 return 1;
82 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
84 e = pthread_rwlock_trywrlock (&r);
85 if (e == 0)
87 puts ("rwlock_trywrlock on rwlock with writer succeeded");
88 return 1;
90 if (e != EBUSY)
92 puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
93 return 1;
95 puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
97 if (pthread_rwlock_unlock (&r) != 0)
99 puts ("1st rwlock_unlock failed");
100 return 1;
102 puts ("1st rwlock_unlock succeeded");
104 if (pthread_rwlock_tryrdlock (&r) != 0)
106 puts ("rwlock_tryrdlock on unlocked rwlock failed");
107 return 1;
109 puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
111 e = pthread_rwlock_trywrlock (&r);
112 if (e == 0)
114 puts ("rwlock_trywrlock on rwlock with reader succeeded");
115 return 1;
117 if (e != EBUSY)
119 puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
120 return 1;
122 puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
124 if (pthread_rwlock_unlock (&r) != 0)
126 puts ("2nd rwlock_unlock failed");
127 return 1;
129 puts ("2nd rwlock_unlock succeeded");
131 if (pthread_rwlock_trywrlock (&r) != 0)
133 puts ("rwlock_trywrlock on unlocked rwlock failed");
134 return 1;
136 puts ("rwlock_trywrlock on unlocked rwlock succeeded");
138 e = pthread_rwlock_tryrdlock (&r);
139 if (e == 0)
141 puts ("rwlock_tryrdlock on rwlock with writer succeeded");
142 return 1;
144 if (e != EBUSY)
146 puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
147 return 1;
149 puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
151 if (pthread_rwlock_unlock (&r) != 0)
153 puts ("3rd rwlock_unlock failed");
154 return 1;
156 puts ("3rd rwlock_unlock succeeded");
158 if (pthread_rwlock_destroy (&r) != 0)
160 puts ("rwlock_destroy failed");
161 return 1;
163 puts ("rwlock_destroy succeeded");
165 return 0;
168 #define TEST_FUNCTION do_test ()
169 #include "../test-skeleton.c"