[vlc-devel] [[PATCH v3] 6/6] threads: no need for varargs in vlc_control_cancel() anymore

Rémi Denis-Courmont remi at remlab.net
Mon Feb 10 14:48:08 CET 2020


No objections.

Le 10 février 2020 15:39:15 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>Either we pass a cleaner (PUSH) or NULL (POP).
>---
> include/vlc_threads.h | 19 ++++++-------------
> src/missing.c         |  4 ++--
> src/os2/thread.c      | 30 ++++++++++--------------------
> src/win32/thread.c    | 30 ++++++++++--------------------
> 4 files changed, 28 insertions(+), 55 deletions(-)
>
>diff --git a/include/vlc_threads.h b/include/vlc_threads.h
>index 68b98b6b335..0e27ea803fa 100644
>--- a/include/vlc_threads.h
>+++ b/include/vlc_threads.h
>@@ -816,13 +816,15 @@ VLC_API int vlc_savecancel(void);
>  */
> VLC_API void vlc_restorecancel(int state);
> 
>+typedef struct vlc_cleanup_t vlc_cleanup_t;
>+
> /**
>  * Internal handler for thread cancellation.
>  *
>  * Do not call this function directly. Use wrapper macros instead:
>  * vlc_cleanup_push(), vlc_cleanup_pop().
>  */
>-VLC_API void vlc_control_cancel(int cmd, ...);
>+VLC_API void vlc_control_cancel(vlc_cleanup_t *);
> 
> /**
>  * Thread handle.
>@@ -1033,12 +1035,6 @@ VLC_API unsigned
>vlc_timer_getoverrun(vlc_timer_t) VLC_USED;
>  */
> VLC_API unsigned vlc_GetCPUCount(void);
> 
>-enum
>-{
>-    VLC_CLEANUP_PUSH,
>-    VLC_CLEANUP_POP,
>-};
>-
> #if defined (LIBVLC_USE_PTHREAD_CLEANUP)
> /**
>  * Registers a thread cancellation handler.
>@@ -1067,9 +1063,7 @@ enum
>  */
> # define vlc_cleanup_pop( ) pthread_cleanup_pop (0)
> 
>-#else
>-typedef struct vlc_cleanup_t vlc_cleanup_t;
>-
>+#else /* !LIBVLC_USE_PTHREAD_CLEANUP */
> struct vlc_cleanup_t
> {
>     vlc_cleanup_t *next;
>@@ -1084,11 +1078,10 @@ struct vlc_cleanup_t
>  */
> # define vlc_cleanup_push( routine, arg ) \
>     do { \
>-        vlc_control_cancel(VLC_CLEANUP_PUSH, \
>-                           &(vlc_cleanup_t){ NULL, routine, arg })
>+        vlc_control_cancel(&(vlc_cleanup_t){ NULL, routine, arg })
> 
> #  define vlc_cleanup_pop( ) \
>-        vlc_control_cancel (VLC_CLEANUP_POP); \
>+        vlc_control_cancel (NULL); \
>     } while (0)
> # else
>/* Those macros do not work in C++. However common C/C++ helpers may
>call them
>diff --git a/src/missing.c b/src/missing.c
>index dcab1b1d6b7..72c60c93159 100644
>--- a/src/missing.c
>+++ b/src/missing.c
>@@ -297,9 +297,9 @@ noreturn update_release_t
>*update_GetRelease(update_t *u)
> 
> #include <vlc_threads.h>
> #if defined(LIBVLC_USE_PTHREAD_CLEANUP)
>-noreturn void vlc_control_cancel (int cmd, ...)
>+noreturn void vlc_control_cancel (vlc_cleanup_t *cleaner)
> {
>-    (void) cmd;
>+    (void) cleaner;
>     vlc_assert_unreachable ();
> }
> #endif
>diff --git a/src/os2/thread.c b/src/os2/thread.c
>index 98a72984afc..7975cd52a7f 100644
>--- a/src/os2/thread.c
>+++ b/src/os2/thread.c
>@@ -749,36 +749,26 @@ void vlc_testcancel (void)
>     }
> }
> 
>-void vlc_control_cancel (int cmd, ...)
>+void vlc_control_cancel (vlc_cleanup_t *cleaner)
> {
>/* NOTE: This function only modifies thread-specific data, so there is
>no
>      * need to lock anything. */
>-    va_list ap;
> 
>     struct vlc_thread *th = vlc_thread_self ();
>     if (th == NULL)
>         return; /* Main thread - cannot be cancelled anyway */
> 
>-    va_start (ap, cmd);
>-    switch (cmd)
>+    if (cleaner != NULL)
>     {
>-        case VLC_CLEANUP_PUSH:
>-        {
>-            /* cleaner is a pointer to the caller stack, no need to
>allocate
>-             * and copy anything. As a nice side effect, this cannot
>fail. */
>-            vlc_cleanup_t *cleaner = va_arg (ap, vlc_cleanup_t *);
>-            cleaner->next = th->cleaners;
>-            th->cleaners = cleaner;
>-            break;
>-        }
>-
>-        case VLC_CLEANUP_POP:
>-        {
>-            th->cleaners = th->cleaners->next;
>-            break;
>-        }
>+        /* cleaner is a pointer to the caller stack, no need to
>allocate
>+            * and copy anything. As a nice side effect, this cannot
>fail. */
>+        cleaner->next = th->cleaners;
>+        th->cleaners = cleaner;
>+    }
>+    else
>+    {
>+        th->cleaners = th->cleaners->next;
>     }
>-    va_end (ap);
> }
> 
>static int vlc_select( int nfds, fd_set *rdset, fd_set *wrset, fd_set
>*exset,
>diff --git a/src/win32/thread.c b/src/win32/thread.c
>index 994bd1631b4..7bc61965195 100644
>--- a/src/win32/thread.c
>+++ b/src/win32/thread.c
>@@ -638,36 +638,26 @@ void vlc_testcancel (void)
>     _endthreadex(0);
> }
> 
>-void vlc_control_cancel (int cmd, ...)
>+void vlc_control_cancel (vlc_cleanup_t *cleaner)
> {
>/* NOTE: This function only modifies thread-specific data, so there is
>no
>      * need to lock anything. */
>-    va_list ap;
> 
>     struct vlc_thread *th = vlc_thread_self();
>     if (th == NULL)
>         return; /* Main thread - cannot be cancelled anyway */
> 
>-    va_start (ap, cmd);
>-    switch (cmd)
>+    if (cleaner != NULL)
>     {
>-        case VLC_CLEANUP_PUSH:
>-        {
>-            /* cleaner is a pointer to the caller stack, no need to
>allocate
>-             * and copy anything. As a nice side effect, this cannot
>fail. */
>-            vlc_cleanup_t *cleaner = va_arg (ap, vlc_cleanup_t *);
>-            cleaner->next = th->cleaners;
>-            th->cleaners = cleaner;
>-            break;
>-        }
>-
>-        case VLC_CLEANUP_POP:
>-        {
>-            th->cleaners = th->cleaners->next;
>-            break;
>-        }
>+        /* cleaner is a pointer to the caller stack, no need to
>allocate
>+            * and copy anything. As a nice side effect, this cannot
>fail. */
>+        cleaner->next = th->cleaners;
>+        th->cleaners = cleaner;
>+    }
>+    else
>+    {
>+        th->cleaners = th->cleaners->next;
>     }
>-    va_end (ap);
> }
> 
> void vlc_cancel_addr_set(atomic_uint *addr)
>-- 
>2.17.1
>
>_______________________________________________
>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/20200210/f68b539e/attachment-0001.html>


More information about the vlc-devel mailing list