1 | /* Copyright (C) 2002-2023 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 <errno.h> |
19 | #include "pthreadP.h" |
20 | #include <shlib-compat.h> |
21 | #include <stap-probe.h> |
22 | |
23 | |
24 | int |
25 | ___pthread_mutex_destroy (pthread_mutex_t *mutex) |
26 | { |
27 | LIBC_PROBE (mutex_destroy, 1, mutex); |
28 | |
29 | /* See concurrency notes regarding __kind in struct __pthread_mutex_s |
30 | in sysdeps/nptl/bits/thread-shared-types.h. */ |
31 | if ((atomic_load_relaxed (&(mutex->__data.__kind)) |
32 | & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0 |
33 | && mutex->__data.__nusers != 0) |
34 | return EBUSY; |
35 | |
36 | /* Set to an invalid value. Relaxed MO is enough as it is undefined behavior |
37 | if the mutex is used after it has been destroyed. But you can reinitialize |
38 | it with pthread_mutex_init. */ |
39 | atomic_store_relaxed (&(mutex->__data.__kind), -1); |
40 | |
41 | return 0; |
42 | } |
43 | versioned_symbol (libc, ___pthread_mutex_destroy, pthread_mutex_destroy, |
44 | GLIBC_2_0); |
45 | libc_hidden_ver (___pthread_mutex_destroy, __pthread_mutex_destroy) |
46 | #ifndef SHARED |
47 | strong_alias (___pthread_mutex_destroy, __pthread_mutex_destroy) |
48 | #endif |
49 | |
50 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34) |
51 | compat_symbol (libpthread, ___pthread_mutex_destroy, __pthread_mutex_destroy, |
52 | GLIBC_2_0); |
53 | #endif |
54 | |