[vlc-commits] adaptive: PlaylistManager: C++ify mutex usage
Alexandre Janniaux
git at videolan.org
Thu Nov 12 14:15:23 CET 2020
vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Sun Nov 1 12:34:20 2020 +0100| [00d383f2b4a1312bd1bc1bdee3a1177d4acb9c00] | committer: Alexandre Janniaux
adaptive: PlaylistManager: C++ify mutex usage
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=00d383f2b4a1312bd1bc1bdee3a1177d4acb9c00
---
modules/demux/adaptive/PlaylistManager.cpp | 30 ++++++++++++++----------------
modules/demux/adaptive/PlaylistManager.h | 6 ++++--
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index c49c748293..2fff6be370 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -51,6 +51,7 @@
using namespace adaptive::http;
using namespace adaptive::logic;
using namespace adaptive;
+using vlc::threads::mutex_locker;
PlaylistManager::PlaylistManager( demux_t *p_demux_,
SharedResources *res,
@@ -75,8 +76,6 @@ PlaylistManager::PlaylistManager( demux_t *p_demux_,
demux.i_firstpcr = VLC_TICK_INVALID;
vlc_mutex_init(&demux.lock);
vlc_cond_init(&demux.cond);
- vlc_mutex_init(&lock);
- vlc_cond_init(&waitcond);
vlc_mutex_init(&cached.lock);
cached.b_live = false;
cached.f_position = 0.0;
@@ -184,16 +183,17 @@ bool PlaylistManager::started() const
void PlaylistManager::stop()
{
- if(b_thread)
+ if(!b_thread)
+ return;
+
{
- vlc_mutex_lock(&lock);
+ mutex_locker locker {lock};
b_canceled = true;
- vlc_cond_signal(&waitcond);
- vlc_mutex_unlock(&lock);
-
- vlc_join(thread, NULL);
- b_thread = false;
+ waitcond.signal();
}
+
+ vlc_join(thread, NULL);
+ b_thread = false;
}
struct PrioritizedAbstractStream
@@ -626,21 +626,20 @@ int PlaylistManager::doControl(int i_query, va_list args)
void PlaylistManager::setBufferingRunState(bool b)
{
- vlc_mutex_lock(&lock);
+ mutex_locker locker {lock};
b_buffering = b;
- vlc_cond_signal(&waitcond);
- vlc_mutex_unlock(&lock);
+ waitcond.signal();
}
void PlaylistManager::Run()
{
- vlc_mutex_lock(&lock);
+ mutex_locker locker {lock};
const vlc_tick_t i_min_buffering = bufferingLogic->getMinBuffering(playlist);
const vlc_tick_t i_extra_buffering = bufferingLogic->getMaxBuffering(playlist) - i_min_buffering;
while(1)
{
while(!b_buffering && !b_canceled)
- vlc_cond_wait(&waitcond, &lock);
+ waitcond.wait(lock);
if (b_canceled)
break;
@@ -675,14 +674,13 @@ void PlaylistManager::Run()
vlc_cond_signal(&demux.cond);
while(b_buffering &&
- vlc_cond_timedwait(&waitcond, &lock, i_deadline) == 0 &&
+ waitcond.timedwait(lock, i_deadline) == 0 &&
i_deadline > vlc_tick_now() &&
!b_canceled);
if (b_canceled)
break;
}
}
- vlc_mutex_unlock(&lock);
}
void * PlaylistManager::managerThread(void *opaque)
diff --git a/modules/demux/adaptive/PlaylistManager.h b/modules/demux/adaptive/PlaylistManager.h
index b925d38efd..d540367636 100644
--- a/modules/demux/adaptive/PlaylistManager.h
+++ b/modules/demux/adaptive/PlaylistManager.h
@@ -26,6 +26,8 @@
#include "Streams.hpp"
#include <vector>
+#include <vlc_cxx_helpers.hpp>
+
namespace adaptive
{
namespace playlist
@@ -133,10 +135,10 @@ namespace adaptive
void setBufferingRunState(bool);
void Run();
static void * managerThread(void *);
- vlc_mutex_t lock;
+ vlc::threads::mutex lock;
+ vlc::threads::condition_variable waitcond;
vlc_thread_t thread;
bool b_thread;
- vlc_cond_t waitcond;
bool b_buffering;
bool b_canceled;
};
More information about the vlc-commits
mailing list