[vlc-commits] upnp: Use vlc::threads

Hugo Beauzée-Luyssen git at videolan.org
Tue Aug 21 13:39:57 CEST 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sat Aug 18 00:18:55 2018 +0200| [f0639004fc70ffe49effc72b58aa71c1c2103cf4] | committer: Hugo Beauzée-Luyssen

upnp: Use vlc::threads

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

 modules/services_discovery/upnp.cpp | 34 ++++++++++++++--------------------
 modules/services_discovery/upnp.hpp |  8 +++++---
 2 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 2281b3aa1a..a4c6ba5479 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -29,6 +29,8 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_threads.h>
+#include <vlc_cxx_helpers.hpp>
 
 #include "upnp.hpp"
 
@@ -923,51 +925,43 @@ Upnp_i11e_cb::Upnp_i11e_cb( Upnp_FunPtr callback, void *cookie )
     , m_cookie( cookie )
 
 {
-    vlc_mutex_init( &m_lock );
-    vlc_sem_init( &m_sem, 0 );
-}
-
-Upnp_i11e_cb::~Upnp_i11e_cb()
-{
-    vlc_mutex_destroy( &m_lock );
-    vlc_sem_destroy( &m_sem );
 }
 
 void Upnp_i11e_cb::waitAndRelease( void )
 {
-    vlc_sem_wait_i11e( &m_sem );
+    m_sem.wait_i11e();
 
-    vlc_mutex_lock( &m_lock );
-    if ( --m_refCount == 0 )
+    int refCount;
+    {
+        vlc::threads::mutex_locker lock( m_lock );
+        refCount = --m_refCount;
+    }
+    if ( refCount == 0 )
     {
         /* The run callback is processed, we can destroy this object */
-        vlc_mutex_unlock( &m_lock );
         delete this;
-    } else
-    {
-        /* Interrupted, let the run callback destroy this object */
-        vlc_mutex_unlock( &m_lock );
     }
+    /* Otherwise interrupted, let the run callback destroy this object */
 }
 
 int Upnp_i11e_cb::run( Upnp_EventType eventType, UpnpEventPtr p_event, void *p_cookie )
 {
     Upnp_i11e_cb *self = static_cast<Upnp_i11e_cb*>( p_cookie );
 
-    vlc_mutex_lock( &self->m_lock );
+    self->m_lock.lock();
     if ( --self->m_refCount == 0 )
     {
         /* Interrupted, we can destroy self */
-        vlc_mutex_unlock( &self->m_lock );
+        self->m_lock.unlock();
         delete self;
         return 0;
     }
     /* Process the user callback_ */
     self->m_callback( eventType, p_event, self->m_cookie);
-    vlc_mutex_unlock( &self->m_lock );
+    self->m_lock.unlock();
 
     /* Signal that the callback is processed */
-    vlc_sem_post( &self->m_sem );
+    self->m_sem.post();
     return 0;
 }
 
diff --git a/modules/services_discovery/upnp.hpp b/modules/services_discovery/upnp.hpp
index 47560ae624..f62e43af0a 100644
--- a/modules/services_discovery/upnp.hpp
+++ b/modules/services_discovery/upnp.hpp
@@ -35,6 +35,8 @@
 #include "upnp-wrapper.hpp"
 
 #include <vlc_url.h>
+#include <vlc_interrupt.h>
+#include <vlc_threads.h>
 
 namespace SD
 {
@@ -87,13 +89,13 @@ class Upnp_i11e_cb
 {
 public:
     Upnp_i11e_cb( Upnp_FunPtr callback, void *cookie );
-    ~Upnp_i11e_cb();
+    ~Upnp_i11e_cb() = default;
     void waitAndRelease( void );
     static int run( Upnp_EventType, UpnpEventPtr, void *);
 
 private:
-    vlc_sem_t       m_sem;
-    vlc_mutex_t     m_lock;
+    vlc::threads::semaphore m_sem;
+    vlc::threads::mutex m_lock;
     int             m_refCount;
     Upnp_FunPtr     m_callback;
     void*           m_cookie;



More information about the vlc-commits mailing list