[vlc-commits] demux: adaptive: use a signaled boolean to test if the thread should stop

Steve Lhomme git at videolan.org
Tue Feb 11 08:23:15 CET 2020


vlc/vlc-3.0 | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Feb 10 16:23:41 2020 +0100| [b7261a3c022ec74929f46451b5f9941b69fe693d] | committer: Steve Lhomme

demux: adaptive: use a signaled boolean to test if the thread should stop

Rather than using a cancelation point that may not work on some platforms.

Ref #23591

(cherry picked from commit 4f094f796aad2cbc3bc41c7f7ccda042c11e819f)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=b7261a3c022ec74929f46451b5f9941b69fe693d
---

 modules/demux/adaptive/PlaylistManager.cpp | 21 +++++++++++++--------
 modules/demux/adaptive/PlaylistManager.h   |  1 +
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index 4aadbe896e..fd9e523990 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -65,6 +65,7 @@ PlaylistManager::PlaylistManager( demux_t *p_demux_,
     failedupdates = 0;
     b_thread = false;
     b_buffering = false;
+    b_canceled = false;
     nextPlaylistupdate = 0;
     demux.i_nzpcr = VLC_TS_INVALID;
     demux.i_firstpcr = VLC_TS_INVALID;
@@ -183,7 +184,11 @@ void PlaylistManager::stop()
 {
     if(b_thread)
     {
-        vlc_cancel(thread);
+        vlc_mutex_lock(&lock);
+        b_canceled = true;
+        vlc_cond_signal(&waitcond);
+        vlc_mutex_unlock(&lock);
+
         vlc_join(thread, NULL);
         b_thread = false;
     }
@@ -641,11 +646,10 @@ void PlaylistManager::Run()
     const unsigned i_extra_buffering = playlist->getMaxBuffering() - i_min_buffering;
     while(1)
     {
-        mutex_cleanup_push(&lock);
-        while(!b_buffering)
+        while(!b_buffering && !b_canceled)
             vlc_cond_wait(&waitcond, &lock);
-        vlc_testcancel();
-        vlc_cleanup_pop();
+        if (b_canceled)
+            break;
 
         if(needsUpdate())
         {
@@ -681,11 +685,12 @@ void PlaylistManager::Run()
             vlc_cond_signal(&demux.cond);
             vlc_mutex_unlock(&demux.lock);
 
-            mutex_cleanup_push(&lock);
             while(b_buffering &&
                     vlc_cond_timedwait(&waitcond, &lock, i_deadline) == 0 &&
-                    i_deadline > mdate());
-            vlc_cleanup_pop();
+                    i_deadline > mdate() &&
+                    !b_canceled);
+            if (b_canceled)
+                break;
         }
     }
     vlc_mutex_unlock(&lock);
diff --git a/modules/demux/adaptive/PlaylistManager.h b/modules/demux/adaptive/PlaylistManager.h
index 27f2f57c98..3f495771d8 100644
--- a/modules/demux/adaptive/PlaylistManager.h
+++ b/modules/demux/adaptive/PlaylistManager.h
@@ -136,6 +136,7 @@ namespace adaptive
             bool         b_thread;
             vlc_cond_t   waitcond;
             bool         b_buffering;
+            bool         b_canceled;
     };
 
 }



More information about the vlc-commits mailing list