[vlc-devel] [PATCH 3/6] upnp: Use vlc::threads
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Mon Aug 20 14:38:17 CEST 2018
---
modules/services_discovery/upnp.cpp | 34 +++++++++++------------------
modules/services_discovery/upnp.hpp | 8 ++++---
2 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 2281b3aa1a..36219b2ec7 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -29,12 +29,12 @@
#endif
#include <vlc_common.h>
+#include <vlc_interrupt.h>
#include "upnp.hpp"
#include <vlc_access.h>
#include <vlc_plugin.h>
-#include <vlc_interrupt.h>
#include <vlc_services_discovery.h>
#include <assert.h>
@@ -923,51 +923,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..c93ae99301 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_threads.h>
+#include <vlc_cxx_helpers.hpp>
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;
--
2.18.0
More information about the vlc-devel
mailing list