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

Rémi Denis-Courmont remi at remlab.net
Mon Sep 7 10:23:04 CEST 2020


Hi,

The _endthreadex() is called indirectly by returning from vlc_entry(). The patch makes it called explicitly but it does bot change the semantics as such. I can add a note though.

Le 7 septembre 2020 08:45:34 GMT+03:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>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
>> 
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200907/0137152b/attachment.html>


More information about the vlc-devel mailing list