]>
Commit | Line | Data |
---|---|---|
6d7e8eda | 1 | /* Copyright (C) 2000-2023 Free Software Foundation, Inc. |
be1dd949 UD |
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 | |
daa3fc9b FW |
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. | |
be1dd949 UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
be1dd949 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
daa3fc9b FW |
15 | License along with the GNU C Library; see the file COPYING.LIB. If |
16 | not, see <https://www.gnu.org/licenses/>. */ | |
be1dd949 | 17 | |
daa3fc9b | 18 | #include <assert.h> |
be1dd949 | 19 | #include <errno.h> |
daa3fc9b | 20 | #include <pthread.h> |
be1dd949 UD |
21 | #include <time.h> |
22 | ||
daa3fc9b FW |
23 | #include "posix-timer.h" |
24 | ||
25 | ||
be1dd949 UD |
26 | /* Delete timer TIMERID. */ |
27 | int | |
28 | timer_delete (timer_t timerid) | |
29 | { | |
daa3fc9b FW |
30 | struct timer_node *timer; |
31 | int retval = -1; | |
32 | ||
33 | pthread_mutex_lock (&__timer_mutex); | |
34 | ||
35 | timer = timer_id2ptr (timerid); | |
36 | if (! timer_valid (timer)) | |
37 | /* Invalid timer ID or the timer is not in use. */ | |
38 | __set_errno (EINVAL); | |
39 | else | |
40 | { | |
41 | if (timer->armed && timer->thread != NULL) | |
42 | { | |
43 | struct thread_node *thread = timer->thread; | |
44 | assert (thread != NULL); | |
45 | ||
46 | /* If thread is cancelled while waiting for handler to terminate, | |
47 | the mutex is unlocked and timer_delete is aborted. */ | |
48 | pthread_cleanup_push (__timer_mutex_cancel_handler, &__timer_mutex); | |
49 | ||
50 | /* If timer is currently being serviced, wait for it to finish. */ | |
51 | while (thread->current_timer == timer) | |
52 | pthread_cond_wait (&thread->cond, &__timer_mutex); | |
53 | ||
54 | pthread_cleanup_pop (0); | |
55 | } | |
56 | ||
57 | /* Remove timer from whatever queue it may be on and deallocate it. */ | |
58 | timer->inuse = TIMER_DELETED; | |
59 | list_unlink_ip (&timer->links); | |
60 | timer_delref (timer); | |
61 | retval = 0; | |
62 | } | |
63 | ||
64 | pthread_mutex_unlock (&__timer_mutex); | |
65 | ||
66 | return retval; | |
be1dd949 | 67 | } |