[vlc-devel] [PATCH 1/1] timer: do not use vlc_cancel()
Thomas Guillem
thomas at gllm.fr
Mon Feb 10 11:39:33 CET 2020
LGTM
On Sun, Feb 9, 2020, at 14:33, RĂ©mi Denis-Courmont wrote:
> ---
> src/posix/timer.c | 25 +++++++++++++------------
> 1 file changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/src/posix/timer.c b/src/posix/timer.c
> index 9acd51db8f..713a9133f5 100644
> --- a/src/posix/timer.c
> +++ b/src/posix/timer.c
> @@ -23,7 +23,6 @@
> #endif
>
> #include <stdatomic.h>
> -#include <stdnoreturn.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <assert.h>
> @@ -47,22 +46,23 @@ struct vlc_timer
> void (*func) (void *);
> void *data;
> vlc_tick_t value, interval;
> + bool live;
> atomic_uint overruns;
> };
>
> -noreturn static void *vlc_timer_thread (void *data)
> +static void *vlc_timer_thread (void *data)
> {
> struct vlc_timer *timer = data;
>
> vlc_mutex_lock (&timer->lock);
> - mutex_cleanup_push (&timer->lock);
>
> - for (;;)
> + while (timer->live)
> {
> - while (timer->value == 0)
> + if (timer->value == 0)
> {
> assert(timer->interval == 0);
> vlc_cond_wait (&timer->reschedule, &timer->lock);
> + continue;
> }
>
> if (timer->interval != 0)
> @@ -94,16 +94,12 @@ noreturn static void *vlc_timer_thread (void *data)
> }
>
> vlc_mutex_unlock (&timer->lock);
> -
> - int canc = vlc_savecancel ();
> timer->func (timer->data);
> - vlc_restorecancel (canc);
> -
> vlc_mutex_lock (&timer->lock);
> }
>
> - vlc_cleanup_pop ();
> - vlc_assert_unreachable ();
> + vlc_mutex_unlock (&timer->lock);
> + return NULL;
> }
>
> int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void
> *data)
> @@ -119,6 +115,7 @@ int vlc_timer_create (vlc_timer_t *id, void (*func)
> (void *), void *data)
> timer->data = data;
> timer->value = 0;
> timer->interval = 0;
> + timer->live = true;
> atomic_init(&timer->overruns, 0);
>
> if (vlc_clone (&timer->thread, vlc_timer_thread, timer,
> @@ -136,7 +133,11 @@ int vlc_timer_create (vlc_timer_t *id, void
> (*func) (void *), void *data)
>
> void vlc_timer_destroy (vlc_timer_t timer)
> {
> - vlc_cancel (timer->thread);
> + vlc_mutex_lock(&timer->lock);
> + timer->live = false;
> + vlc_cond_signal(&timer->reschedule);
> + vlc_mutex_unlock(&timer->lock);
> +
> vlc_join (timer->thread, NULL);
> vlc_cond_destroy (&timer->reschedule);
> vlc_mutex_destroy (&timer->lock);
> --
> 2.25.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list