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

Steve Lhomme robux4 at ycbcr.xyz
Tue Feb 11 10:01:05 CET 2020


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



More information about the vlc-devel mailing list