[vlc-devel] [PATCH 3/7] posix: remove cancellation in vlc_atomic_wait()
Marvin Scholz
epirat07 at gmail.com
Tue Apr 14 21:53:40 CEST 2020
On 14 Apr 2020, at 21:45, RĂ©mi Denis-Courmont wrote:
> ---
> src/posix/wait.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/src/posix/wait.c b/src/posix/wait.c
> index dfb0c508db..380e3cf5e7 100644
> --- a/src/posix/wait.c
> +++ b/src/posix/wait.c
> @@ -66,10 +66,8 @@ static struct wait_bucket
> *wait_bucket_enter(atomic_uint *addr)
> return bucket;
> }
>
> -static void wait_bucket_leave(void *data)
> +static void wait_bucket_leave(struct wait_bucker *bucket)
Isn't there a typo, wait_bucker instead of wait_bucket?
> {
> - struct wait_bucket *bucket = data;
> -
> bucket->waiters--;
> pthread_mutex_unlock(&bucket->lock);
> }
> @@ -79,14 +77,15 @@ void vlc_atomic_wait(void *addr, unsigned value)
> atomic_uint *futex = addr;
> struct wait_bucket *bucket = wait_bucket_enter(futex);
>
> - pthread_cleanup_push(wait_bucket_leave, bucket);
> + if (value == atomic_load_explicit(futex, memory_order_relaxed)) {
> + int canc;
>
> - if (value == atomic_load_explicit(futex, memory_order_relaxed))
> + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &canc);
> pthread_cond_wait(&bucket->wait, &bucket->lock);
> - else
> - pthread_testcancel();
> + pthread_setcancelstate(canc, NULL);
> + }
>
> - pthread_cleanup_pop(1);
> + wait_bucket_leave(bucket);
> }
>
> static int vlc_atomic_timedwait_timespec(void *addr, unsigned value,
> @@ -96,14 +95,15 @@ static int vlc_atomic_timedwait_timespec(void
> *addr, unsigned value,
> struct wait_bucket *bucket = wait_bucket_enter(futex);
> int ret = 0;
>
> - pthread_cleanup_push(wait_bucket_leave, bucket);
> + if (value == atomic_load_explicit(futex, memory_order_relaxed)) {
> + int canc;
>
> - if (value == atomic_load_explicit(futex, memory_order_relaxed))
> + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &canc);
> ret = pthread_cond_timedwait(&bucket->wait, &bucket->lock,
> ts);
> - else
> - pthread_testcancel();
> + pthread_setcancelstate(canc, NULL);
> + }
>
> - pthread_cleanup_pop(1);
> + wait_bucket_leave(bucket);
> return ret;
> }
>
> --
> 2.26.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