GLIBC-SA-2024-0004: add commit for 2.31 branch
[glibc.git] / sysdeps / unix / sysv / linux / timer_delete.c
blobad397e5ce6939cca8ad70b6905e368509c5e93fb
1 /* Copyright (C) 2003-2024 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 License as
6 published by the Free Software Foundation; either version 2.1 of the
7 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; see the file COPYING.LIB. If
16 not, see <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <stdlib.h>
20 #include <time.h>
21 #include <sysdep.h>
22 #include "kernel-posix-timers.h"
23 #include <pthreadP.h>
24 #include <shlib-compat.h>
26 int
27 ___timer_delete (timer_t timerid)
29 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
30 int res = INLINE_SYSCALL_CALL (timer_delete, ktimerid);
32 if (res == 0)
34 if (timer_is_sigev_thread (timerid))
36 struct timer *kt = timerid_to_timer (timerid);
38 /* Remove the timer from the list. */
39 __pthread_mutex_lock (&__timer_active_sigev_thread_lock);
40 if (__timer_active_sigev_thread == kt)
41 __timer_active_sigev_thread = kt->next;
42 else
44 struct timer *prevp = __timer_active_sigev_thread;
45 while (prevp->next != NULL)
46 if (prevp->next == kt)
48 prevp->next = kt->next;
49 break;
51 else
52 prevp = prevp->next;
54 __pthread_mutex_unlock (&__timer_active_sigev_thread_lock);
56 free (kt);
59 return 0;
62 /* The kernel timer is not known or something else bad happened.
63 Return the error. */
64 return -1;
66 versioned_symbol (libc, ___timer_delete, timer_delete, GLIBC_2_34);
67 libc_hidden_ver (___timer_delete, __timer_delete)
69 #if TIMER_T_WAS_INT_COMPAT
70 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_3, GLIBC_2_34)
71 compat_symbol (librt, ___timer_delete, timer_delete, GLIBC_2_3_3);
72 #endif
74 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
75 int
76 __timer_delete_old (int timerid)
78 int res = __timer_delete (__timer_compat_list[timerid]);
80 if (res == 0)
81 /* Successful timer deletion, now free the index. We only need to
82 store a word and that better be atomic. */
83 __timer_compat_list[timerid] = NULL;
85 return res;
87 compat_symbol (librt, __timer_delete_old, timer_delete, GLIBC_2_2);
88 # endif /* OTHER_SHLIB_COMPAT */
90 #else /* !TIMER_T_WAS_INT_COMPAT */
91 /* The transition from int to timer_t did not change ABI because the
92 type sizes are the same. */
93 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
94 compat_symbol (librt, ___timer_delete, timer_delete, GLIBC_2_2);
95 # endif
96 #endif /* !TIMER_T_WAS_INT_COMPAT */