[vlc-devel] [PATCH 1/2] win32: factor thread exit code
RĂ©mi Denis-Courmont
remi at remlab.net
Sun Sep 6 19:12:25 CEST 2020
---
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
More information about the vlc-devel
mailing list