1/* Copyright (C) 2002-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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/>. */
17
18#include <pthread.h>
19#include <stdio.h>
20
21
22static int
23do_test (void)
24{
25 pthread_rwlock_t r;
26
27 if (pthread_rwlock_init (rwlock: &r, NULL) != 0)
28 {
29 puts (s: "rwlock_init failed");
30 return 1;
31 }
32 puts (s: "rwlock_init succeeded");
33
34 if (pthread_rwlock_rdlock (rwlock: &r) != 0)
35 {
36 puts (s: "1st rwlock_rdlock failed");
37 return 1;
38 }
39 puts (s: "1st rwlock_rdlock succeeded");
40
41 if (pthread_rwlock_rdlock (rwlock: &r) != 0)
42 {
43 puts (s: "2nd rwlock_rdlock failed");
44 return 1;
45 }
46 puts (s: "2nd rwlock_rdlock succeeded");
47
48 if (pthread_rwlock_unlock (rwlock: &r) != 0)
49 {
50 puts (s: "1st rwlock_unlock failed");
51 return 1;
52 }
53 puts (s: "1st rwlock_unlock succeeded");
54
55 if (pthread_rwlock_unlock (rwlock: &r) != 0)
56 {
57 puts (s: "2nd rwlock_unlock failed");
58 return 1;
59 }
60 puts (s: "2nd rwlock_unlock succeeded");
61
62 if (pthread_rwlock_wrlock (rwlock: &r) != 0)
63 {
64 puts (s: "1st rwlock_wrlock failed");
65 return 1;
66 }
67 puts (s: "1st rwlock_wrlock succeeded");
68
69 if (pthread_rwlock_unlock (rwlock: &r) != 0)
70 {
71 puts (s: "3rd rwlock_unlock failed");
72 return 1;
73 }
74 puts (s: "3rd rwlock_unlock succeeded");
75
76 if (pthread_rwlock_wrlock (rwlock: &r) != 0)
77 {
78 puts (s: "2nd rwlock_wrlock failed");
79 return 1;
80 }
81 puts (s: "2nd rwlock_wrlock succeeded");
82
83 if (pthread_rwlock_unlock (rwlock: &r) != 0)
84 {
85 puts (s: "4th rwlock_unlock failed");
86 return 1;
87 }
88 puts (s: "4th rwlock_unlock succeeded");
89
90 if (pthread_rwlock_rdlock (rwlock: &r) != 0)
91 {
92 puts (s: "3rd rwlock_rdlock failed");
93 return 1;
94 }
95 puts (s: "3rd rwlock_rdlock succeeded");
96
97 if (pthread_rwlock_unlock (rwlock: &r) != 0)
98 {
99 puts (s: "5th rwlock_unlock failed");
100 return 1;
101 }
102 puts (s: "5th rwlock_unlock succeeded");
103
104 if (pthread_rwlock_destroy (rwlock: &r) != 0)
105 {
106 puts (s: "rwlock_destroy failed");
107 return 1;
108 }
109 puts (s: "rwlock_destroy succeeded");
110
111 return 0;
112}
113
114#define TEST_FUNCTION do_test ()
115#include "../test-skeleton.c"
116

source code of glibc/sysdeps/pthread/tst-rwlock1.c