[vlc-devel] [PATCH 2/6] demux/adaptive: Downloader::Run: simplify

Filip Roséen filip at atch.se
Thu May 18 17:07:32 CEST 2017


There is absolutely no need to lock and unlock the mutex on every
iteration, especially given that one cannot observe this behavior (as
there is nothing at all that guarantees that something can aquire the
lock inbetween those two calls).

There is also no need to check if we are killed twice, once is
sufficient
---
 modules/demux/adaptive/http/Downloader.cpp | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/modules/demux/adaptive/http/Downloader.cpp b/modules/demux/adaptive/http/Downloader.cpp
index 164ad743dc..948f425879 100644
--- a/modules/demux/adaptive/http/Downloader.cpp
+++ b/modules/demux/adaptive/http/Downloader.cpp
@@ -89,16 +89,11 @@ void Downloader::DownloadSource(HTTPChunkBufferedSource *source)
 
 void Downloader::Run()
 {
+    vlc_mutex_lock(&lock);
     while(1)
     {
-        vlc_mutex_lock(&lock);
-        if(killed)
-            break;
-
         while(chunks.empty() && !killed)
-        {
             vlc_cond_wait(&waitcond, &lock);
-        }
 
         if(killed)
             break;
@@ -110,8 +105,6 @@ void Downloader::Run()
             if(source->isDone())
                 chunks.pop_front();
         }
-
-        vlc_mutex_unlock(&lock);
     }
     vlc_mutex_unlock(&lock);
 }
-- 
2.12.2


More information about the vlc-devel mailing list