1 | /* Copyright (C) 2003-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. |
4 | |
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 License as |
7 | published by the Free Software Foundation; either version 2.1 of the |
8 | License, or (at your option) any later version. |
9 | |
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. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; see the file COPYING.LIB. If |
17 | not, see <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <errno.h> |
20 | #include <stdlib.h> |
21 | #include <time.h> |
22 | #include <sysdep.h> |
23 | #include "kernel-posix-timers.h" |
24 | #include <pthreadP.h> |
25 | #include <shlib-compat.h> |
26 | |
27 | int |
28 | ___timer_delete (timer_t timerid) |
29 | { |
30 | kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid); |
31 | int res = INLINE_SYSCALL_CALL (timer_delete, ktimerid); |
32 | |
33 | if (res == 0) |
34 | { |
35 | if (timer_is_sigev_thread (timerid)) |
36 | { |
37 | struct timer *kt = timerid_to_timer (timerid); |
38 | |
39 | /* Remove the timer from the list. */ |
40 | __pthread_mutex_lock (&__timer_active_sigev_thread_lock); |
41 | if (__timer_active_sigev_thread == kt) |
42 | __timer_active_sigev_thread = kt->next; |
43 | else |
44 | { |
45 | struct timer *prevp = __timer_active_sigev_thread; |
46 | while (prevp->next != NULL) |
47 | if (prevp->next == kt) |
48 | { |
49 | prevp->next = kt->next; |
50 | break; |
51 | } |
52 | else |
53 | prevp = prevp->next; |
54 | } |
55 | __pthread_mutex_unlock (&__timer_active_sigev_thread_lock); |
56 | |
57 | free (kt); |
58 | } |
59 | |
60 | return 0; |
61 | } |
62 | |
63 | /* The kernel timer is not known or something else bad happened. |
64 | Return the error. */ |
65 | return -1; |
66 | } |
67 | versioned_symbol (libc, ___timer_delete, timer_delete, GLIBC_2_34); |
68 | libc_hidden_ver (___timer_delete, __timer_delete) |
69 | |
70 | #if TIMER_T_WAS_INT_COMPAT |
71 | # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_3, GLIBC_2_34) |
72 | compat_symbol (librt, ___timer_delete, timer_delete, GLIBC_2_3_3); |
73 | #endif |
74 | |
75 | # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3) |
76 | int |
77 | __timer_delete_old (int timerid) |
78 | { |
79 | int res = __timer_delete (__timer_compat_list[timerid]); |
80 | |
81 | if (res == 0) |
82 | /* Successful timer deletion, now free the index. We only need to |
83 | store a word and that better be atomic. */ |
84 | __timer_compat_list[timerid] = NULL; |
85 | |
86 | return res; |
87 | } |
88 | compat_symbol (librt, __timer_delete_old, timer_delete, GLIBC_2_2); |
89 | # endif /* OTHER_SHLIB_COMPAT */ |
90 | |
91 | #else /* !TIMER_T_WAS_INT_COMPAT */ |
92 | /* The transition from int to timer_t did not change ABI because the |
93 | type sizes are the same. */ |
94 | # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34) |
95 | compat_symbol (librt, ___timer_delete, timer_delete, GLIBC_2_2); |
96 | # endif |
97 | #endif /* !TIMER_T_WAS_INT_COMPAT */ |
98 | |