1 /* Copyright (C) 2003-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
20 #include <futex-internal.h>
23 #include <stap-probe.h>
25 #include "pthread_rwlock_common.c"
27 /* See pthread_rwlock_common.c for an overview. */
29 ___pthread_rwlock_unlock (pthread_rwlock_t
*rwlock
)
31 LIBC_PROBE (rwlock_unlock
, 1, rwlock
);
33 /* We distinguish between having acquired a read vs. a write lock by looking
34 at the writer TID. If it's equal to our TID, we must be the writer
35 because nobody else can have stored this value. Also, if we are a
36 reader, we will read from the wrunlock store with value 0 by the most
37 recent writer because that writer happens-before us. */
38 if (atomic_load_relaxed (&rwlock
->__data
.__cur_writer
)
39 == THREAD_GETMEM (THREAD_SELF
, tid
))
40 __pthread_rwlock_wrunlock (rwlock
);
42 __pthread_rwlock_rdunlock (rwlock
);
45 versioned_symbol (libc
, ___pthread_rwlock_unlock
, pthread_rwlock_unlock
,
47 strong_alias (___pthread_rwlock_unlock
, __pthread_rwlock_unlock
)
48 libc_hidden_ver (___pthread_rwlock_unlock
, __pthread_rwlock_unlock
)
50 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1, GLIBC_2_34)
51 compat_symbol (libpthread
, ___pthread_rwlock_unlock
, pthread_rwlock_unlock
,
54 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_2, GLIBC_2_34)
55 compat_symbol (libpthread
, ___pthread_rwlock_unlock
, __pthread_rwlock_unlock
,