1 /* Helper program for testing the pthread_rwlock_t and pthread_rwlockattr_t
4 Copyright (C) 2016-2024 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <https://www.gnu.org/licenses/>. */
21 /* Keep the calls to the pthread_* functions on separate lines to make it easy
22 to advance through the program using the gdb 'next' command. */
29 /* Need these so we don't have lines longer than 79 chars. */
30 #define SET_KIND(attr, kind) pthread_rwlockattr_setkind_np (attr, kind)
31 #define SET_SHARED(attr, shared) pthread_rwlockattr_setpshared (attr, shared)
33 static int rwlock_reinit (pthread_rwlock_t
*rwlock
,
34 const pthread_rwlockattr_t
*attr
);
35 static int test_setkind_np (pthread_rwlock_t
*rwlock
,
36 pthread_rwlockattr_t
*attr
);
37 static int test_setpshared (pthread_rwlock_t
*rwlock
,
38 pthread_rwlockattr_t
*attr
);
43 pthread_rwlock_t rwlock
;
44 pthread_rwlockattr_t attr
;
47 if (pthread_rwlockattr_init (&attr
) == 0
48 && pthread_rwlock_init (&rwlock
, NULL
) == 0
49 && test_setkind_np (&rwlock
, &attr
) == PASS
50 && test_setpshared (&rwlock
, &attr
) == PASS
)
52 /* Else, one of the pthread_rwlock* functions failed. */
57 /* Destroys RWLOCK and re-initializes it using ATTR. */
59 rwlock_reinit (pthread_rwlock_t
*rwlock
, const pthread_rwlockattr_t
*attr
)
63 if (pthread_rwlock_destroy (rwlock
) == 0
64 && pthread_rwlock_init (rwlock
, attr
) == 0)
70 /* Tests setting whether the rwlock prefers readers or writers. */
72 test_setkind_np (pthread_rwlock_t
*rwlock
, pthread_rwlockattr_t
*attr
)
76 if (SET_KIND (attr
, PTHREAD_RWLOCK_PREFER_READER_NP
) == 0 /* Set kind. */
77 && rwlock_reinit (rwlock
, attr
) == PASS
78 && SET_KIND (attr
, PTHREAD_RWLOCK_PREFER_WRITER_NP
) == 0
79 && rwlock_reinit (rwlock
, attr
) == PASS
80 && SET_KIND (attr
, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
) == 0
81 && rwlock_reinit (rwlock
, attr
) == PASS
)
87 /* Tests setting whether the rwlock can be shared between processes. */
89 test_setpshared (pthread_rwlock_t
*rwlock
, pthread_rwlockattr_t
*attr
)
93 if (SET_SHARED (attr
, PTHREAD_PROCESS_SHARED
) == 0 /* Set shared. */
94 && rwlock_reinit (rwlock
, attr
) == PASS
95 && SET_SHARED (attr
, PTHREAD_PROCESS_PRIVATE
) == 0
96 && rwlock_reinit (rwlock
, attr
) == PASS
)