[vlc-devel] [PATCH 1/2] demux: adaptive: avoid using a bool telling if the thread is not created

Rémi Denis-Courmont remi at remlab.net
Tue Feb 11 13:09:05 CET 2020


Hi,

You could change vlc_thread_t to a pointer type on all platforms.

You could even make vlc_join(NULL, ...) a no-op to simplify error paths.

But this requires changing some of the platform code first.

Le 11 février 2020 11:01:05 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>We already have a variable to store it.
>---
> modules/demux/adaptive/PlaylistManager.cpp | 18 ++++++++++--------
> modules/demux/adaptive/PlaylistManager.h   |  1 -
> 2 files changed, 10 insertions(+), 9 deletions(-)
>
>diff --git a/modules/demux/adaptive/PlaylistManager.cpp
>b/modules/demux/adaptive/PlaylistManager.cpp
>index a8bce7aca19..62c697e1432 100644
>--- a/modules/demux/adaptive/PlaylistManager.cpp
>+++ b/modules/demux/adaptive/PlaylistManager.cpp
>@@ -62,7 +62,7 @@ PlaylistManager::PlaylistManager( demux_t *p_demux_,
>     currentPeriod = playlist->getFirstPeriod();
>     resources = res;
>     failedupdates = 0;
>-    b_thread = false;
>+    thread = nullptr;
>     b_buffering = false;
>     b_canceled = false;
>     nextPlaylistupdate = 0;
>@@ -159,13 +159,15 @@ bool PlaylistManager::init()
> 
> bool PlaylistManager::start()
> {
>-    if(b_thread)
>+    if (thread != nullptr)
>         return false;
> 
>-    b_thread = !vlc_clone(&thread, managerThread,
>-                          static_cast<void *>(this),
>VLC_THREAD_PRIORITY_INPUT);
>-    if(!b_thread)
>+    if (!vlc_clone(&thread, managerThread,
>+                   static_cast<void *>(this),
>VLC_THREAD_PRIORITY_INPUT))
>+    {
>+        thread = nullptr;
>         return false;
>+    }
> 
>     setBufferingRunState(true);
> 
>@@ -174,12 +176,12 @@ bool PlaylistManager::start()
> 
> bool PlaylistManager::started() const
> {
>-    return b_thread;
>+    return thread != nullptr;
> }
> 
> void PlaylistManager::stop()
> {
>-    if(b_thread)
>+    if(thread != nullptr)
>     {
>         vlc_mutex_lock(&lock);
>         b_canceled = true;
>@@ -187,7 +189,7 @@ void PlaylistManager::stop()
>         vlc_mutex_unlock(&lock);
> 
>         vlc_join(thread, NULL);
>-        b_thread = false;
>+        thread = nullptr;
>     }
> }
> 
>diff --git a/modules/demux/adaptive/PlaylistManager.h
>b/modules/demux/adaptive/PlaylistManager.h
>index 55ceacde7c9..501200f9b7a 100644
>--- a/modules/demux/adaptive/PlaylistManager.h
>+++ b/modules/demux/adaptive/PlaylistManager.h
>@@ -132,7 +132,6 @@ namespace adaptive
>             static void * managerThread(void *);
>             vlc_mutex_t  lock;
>             vlc_thread_t thread;
>-            bool         b_thread;
>             vlc_cond_t   waitcond;
>             bool         b_buffering;
>             bool         b_canceled;
>-- 
>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/20200211/32405081/attachment.html>


More information about the vlc-devel mailing list