Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / tst-rwlock1.c
blobcf873c49e8321baa5e5ece9e457bd1bdccc692ee
1 /* Copyright (C) 2002-2014 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 <http://www.gnu.org/licenses/>. */
19 #include <pthread.h>
20 #include <stdio.h>
23 static int
24 do_test (void)
26 pthread_rwlock_t r;
28 if (pthread_rwlock_init (&r, NULL) != 0)
30 puts ("rwlock_init failed");
31 return 1;
33 puts ("rwlock_init succeeded");
35 if (pthread_rwlock_rdlock (&r) != 0)
37 puts ("1st rwlock_rdlock failed");
38 return 1;
40 puts ("1st rwlock_rdlock succeeded");
42 if (pthread_rwlock_rdlock (&r) != 0)
44 puts ("2nd rwlock_rdlock failed");
45 return 1;
47 puts ("2nd rwlock_rdlock succeeded");
49 if (pthread_rwlock_unlock (&r) != 0)
51 puts ("1st rwlock_unlock failed");
52 return 1;
54 puts ("1st rwlock_unlock succeeded");
56 if (pthread_rwlock_unlock (&r) != 0)
58 puts ("2nd rwlock_unlock failed");
59 return 1;
61 puts ("2nd rwlock_unlock succeeded");
63 if (pthread_rwlock_wrlock (&r) != 0)
65 puts ("1st rwlock_wrlock failed");
66 return 1;
68 puts ("1st rwlock_wrlock succeeded");
70 if (pthread_rwlock_unlock (&r) != 0)
72 puts ("3rd rwlock_unlock failed");
73 return 1;
75 puts ("3rd rwlock_unlock succeeded");
77 if (pthread_rwlock_wrlock (&r) != 0)
79 puts ("2nd rwlock_wrlock failed");
80 return 1;
82 puts ("2nd rwlock_wrlock succeeded");
84 if (pthread_rwlock_unlock (&r) != 0)
86 puts ("4th rwlock_unlock failed");
87 return 1;
89 puts ("4th rwlock_unlock succeeded");
91 if (pthread_rwlock_rdlock (&r) != 0)
93 puts ("3rd rwlock_rdlock failed");
94 return 1;
96 puts ("3rd rwlock_rdlock succeeded");
98 if (pthread_rwlock_unlock (&r) != 0)
100 puts ("5th rwlock_unlock failed");
101 return 1;
103 puts ("5th rwlock_unlock succeeded");
105 if (pthread_rwlock_destroy (&r) != 0)
107 puts ("rwlock_destroy failed");
108 return 1;
110 puts ("rwlock_destroy succeeded");
112 return 0;
115 #define TEST_FUNCTION do_test ()
116 #include "../test-skeleton.c"