<div dir="ltr">Ping...</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 21, 2017 at 10:23 PM, Zhao Zhili <span dir="ltr"><<a href="mailto:wantlamy@gmail.com" target="_blank">wantlamy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p>---<br> modules/demux/adaptive/http/<wbr>Downloader.cpp | 21 +++++++++++++++------<br> modules/demux/adaptive/http/<wbr>Downloader.hpp | 4 +++-<br> 2 files changed, 18 insertions(+), 7 deletions(-)</p><p>diff --git a/modules/demux/adaptive/http/<wbr>Downloader.cpp b/modules/demux/adaptive/http/<wbr>Downloader.cpp<br>index ba81727..b2e64ef 100644<br>--- a/modules/demux/adaptive/http/<wbr>Downloader.cpp<br>+++ b/modules/demux/adaptive/http/<wbr>Downloader.cpp<br>@@ -28,12 +28,13 @@<br> <br> using namespace adaptive::http;<br> <br>-Downloader::Downloader()<br>+Downloader::Downloader() :<br>+ thread_handle_valid(false),<br>+ killed(false),<br>+ pending_requests(0)<br> {<br> vlc_mutex_init(&lock);<br> vlc_cond_init(&waitcond);<br>- killed = false;<br>- thread_handle_valid = false;<br> }<br> <br> bool Downloader::start()<br>@@ -50,8 +51,8 @@ bool Downloader::start()<br> <br> Downloader::~Downloader()<br> {<br>+ killed.store(true);<br> vlc_mutex_lock( &lock );<br>- killed = true;<br> vlc_cond_signal(&waitcond);<br> vlc_mutex_unlock( &lock );<br> <br>@@ -62,18 +63,23 @@ Downloader::~Downloader()<br> }<br> void Downloader::schedule(<wbr>HTTPChunkBufferedSource *source)<br> {<br>+ pending_requests.fetch_add(1);<br> vlc_mutex_lock(&lock);<br> source->hold();<br> chunks.push_back(source);<br>+ pending_requests.fetch_sub(1);<br> vlc_cond_signal(&waitcond);<br> vlc_mutex_unlock(&lock);<br> }<br> <br> void Downloader::cancel(<wbr>HTTPChunkBufferedSource *source)<br> {<br>+ pending_requests.fetch_add(1);<br> vlc_mutex_lock(&lock);<br> source->release();<br> chunks.remove(source);<br>+ pending_requests.fetch_sub(1);<br>+ vlc_cond_signal(&waitcond);<br> vlc_mutex_unlock(&lock);<br> }<br> <br>@@ -97,10 +103,13 @@ void Downloader::Run()<br> vlc_mutex_lock(&lock);<br> while(1)<br> {<br>- while(chunks.empty() && !killed)<br>+ while(chunks.empty() && killed.load() == false)<br>+ vlc_cond_wait(&waitcond, &lock);<br>+<br>+ while(pending_requests.load() > 0 && killed.load() == false)<br> vlc_cond_wait(&waitcond, &lock);<br> <br>- if(killed)<br>+ if(killed.load())<br> break;<br> <br> if(!chunks.empty())<br>diff --git a/modules/demux/adaptive/http/<wbr>Downloader.hpp b/modules/demux/adaptive/http/<wbr>Downloader.hpp<br>index 1d6cc57..ec76b3f 100644<br>--- a/modules/demux/adaptive/http/<wbr>Downloader.hpp<br>+++ b/modules/demux/adaptive/http/<wbr>Downloader.hpp<br>@@ -23,6 +23,7 @@<br> #include "Chunk.h"<br> <br> #include <vlc_common.h><br>+#include <atomic><br> #include <list><br> <br> namespace adaptive<br>@@ -48,7 +49,8 @@ namespace adaptive<br> vlc_mutex_t lock;<br> vlc_cond_t waitcond;<br> bool thread_handle_valid;<br>- bool killed;<br>+ std::atomic_bool killed;<br>+ std::atomic_int pending_requests;<br> std::list<<wbr>HTTPChunkBufferedSource *> chunks;<br> };<span class="HOEnZb"><font color="#888888"><br> <br>-- <br>2.7.4<span><span><br></span></span></font></span></p></div>
</blockquote></div><br></div>