[vlc-devel] [PATCH 1/2] win32: factor thread exit code

Steve Lhomme robux4 at ycbcr.xyz
Mon Sep 7 07:45:34 CEST 2020


I think the title is misleading. It's not just code factoring. A regular 
thread not calling test_cancel() will now call ExitThread. It's probably 
right, but it has some side effects that should be mentioned:

"When this function is called (either explicitly or by returning from a 
thread procedure), the current thread's stack is deallocated, all 
pending I/O initiated by the thread is canceled, and the thread 
terminates. The entry-point function of all attached dynamic-link 
libraries (DLLs) is invoked with a value indicating that the thread is 
detaching from the DLL."

On 2020-09-06 19:12, RĂ©mi Denis-Courmont wrote:
> ---
>   src/win32/thread.c | 27 ++++++++++++++++-----------
>   1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/src/win32/thread.c b/src/win32/thread.c
> index 255946913c..cd15828128 100644
> --- a/src/win32/thread.c
> +++ b/src/win32/thread.c
> @@ -35,6 +35,7 @@
>   #include "libvlc.h"
>   #include <stdarg.h>
>   #include <stdatomic.h>
> +#include <stdnoreturn.h>
>   #include <assert.h>
>   #include <limits.h>
>   #include <errno.h>
> @@ -345,6 +346,18 @@ static void vlc_thread_destroy(vlc_thread_t th)
>       free(th);
>   }
>   
> +static noreturn void vlc_thread_exit(vlc_thread_t self)
> +{
> +    if (self->id == NULL) /* Detached thread */
> +        vlc_thread_destroy(self);
> +
> +#if VLC_WINSTORE_APP
> +    ExitThread(0);
> +#else // !VLC_WINSTORE_APP
> +    _endthreadex(0);
> +#endif // !VLC_WINSTORE_APP
> +}
> +
>   static
>   #if VLC_WINSTORE_APP
>   DWORD
> @@ -359,10 +372,7 @@ __stdcall vlc_entry (void *p)
>       th->killable = true;
>       th->data = th->entry (th->data);
>       TlsSetValue(thread_key, NULL);
> -
> -    if (th->id == NULL) /* Detached thread */
> -        vlc_thread_destroy(th);
> -    return 0;
> +    vlc_thread_exit(th);
>   }
>   
>   static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,
> @@ -524,13 +534,8 @@ void vlc_testcancel (void)
>           p->proc (p->data);
>   
>       th->data = NULL; /* TODO: special value? */
> -    if (th->id == NULL) /* Detached thread */
> -        vlc_thread_destroy(th);
> -#if VLC_WINSTORE_APP
> -    ExitThread(0);
> -#else // !VLC_WINSTORE_APP
> -    _endthreadex(0);
> -#endif // !VLC_WINSTORE_APP
> +
> +    vlc_thread_exit(th);
>   }
>   
>   void vlc_control_cancel (vlc_cleanup_t *cleaner)
> -- 
> 2.28.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