[vlc-commits] sap: merge global and per-instance locks

Rémi Denis-Courmont git at videolan.org
Fri Jun 20 19:01:26 CEST 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Jun 20 19:52:03 2014 +0300| [82870e2ea0aaf6b36f05f5964114bbdf27c09a92] | committer: Rémi Denis-Courmont

sap: merge global and per-instance locks

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

 src/stream_output/sap.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c
index 6a37bc9..c52de43 100644
--- a/src/stream_output/sap.c
+++ b/src/stream_output/sap.c
@@ -75,10 +75,11 @@ struct sap_handler_t
 {
     VLC_COMMON_MEMBERS
 
-    vlc_mutex_t    lock;
     sap_address_t *first;
 };
 
+static vlc_mutex_t sap_mutex = VLC_STATIC_MUTEX;
+
 #define SAP_MAX_BUFFER 65534
 #define MIN_INTERVAL 2
 #define MAX_INTERVAL 300
@@ -99,7 +100,6 @@ static sap_handler_t *SAP_Create (vlc_object_t *p_announce)
     if (p_sap == NULL)
         return NULL;
 
-    vlc_mutex_init (&p_sap->lock);
     p_sap->first = NULL;
     return p_sap;
 }
@@ -107,7 +107,6 @@ static sap_handler_t *SAP_Create (vlc_object_t *p_announce)
 static void SAP_Destroy (sap_handler_t *p_sap)
 {
     assert (p_sap->first == NULL);
-    vlc_mutex_destroy (&p_sap->lock);
     vlc_object_release (p_sap);
 }
 
@@ -299,7 +298,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap,
     /* Find/create SAP address thread */
     msg_Dbg( p_sap, "using SAP address: %s", psz_addr);
 
-    vlc_mutex_lock (&p_sap->lock);
+    vlc_mutex_lock (&sap_mutex);
     sap_address_t *sap_addr;
     for (sap_addr = p_sap->first; sap_addr; sap_addr = sap_addr->next)
         if (!strcmp (psz_addr, sap_addr->group))
@@ -310,7 +309,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap,
         sap_addr = AddressCreate (VLC_OBJECT(p_sap), psz_addr);
         if (sap_addr == NULL)
         {
-            vlc_mutex_unlock (&p_sap->lock);
+            vlc_mutex_unlock (&sap_mutex);
             return NULL;
         }
         sap_addr->next = p_sap->first;
@@ -319,7 +318,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap,
     /* Switch locks.
      * NEVER take the global SAP lock when holding a SAP thread lock! */
     vlc_mutex_lock (&sap_addr->lock);
-    vlc_mutex_unlock (&p_sap->lock);
+    vlc_mutex_unlock (&sap_mutex);
 
     size_t length = 20;
     switch (sap_addr->orig.ss_family)
@@ -402,7 +401,7 @@ static void SAP_Del (sap_handler_t *p_sap, session_descriptor_t *session)
     sap_address_t *addr, **paddr;
     session_descriptor_t **psession;
 
-    vlc_mutex_lock (&p_sap->lock);
+    vlc_mutex_lock (&sap_mutex);
     paddr = &p_sap->first;
     for (;;)
     {
@@ -427,7 +426,7 @@ found:
     if (addr->first == NULL)
         /* Last session for this address -> unlink the address */
         *paddr = addr->next;
-    vlc_mutex_unlock (&p_sap->lock);
+    vlc_mutex_unlock (&sap_mutex);
 
     if (addr->first == NULL)
     {
@@ -456,8 +455,6 @@ static void sap_destroy (vlc_object_t *p_this)
 
 #undef sout_AnnounceRegisterSDP
 
-static vlc_mutex_t sap_mutex = VLC_STATIC_MUTEX;
-
 /**
  *  Registers a new session with the announce handler, using a pregenerated SDP
  *



More information about the vlc-commits mailing list