Commit 82870e2e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

sap: merge global and per-instance locks

parent cb22edf6
...@@ -75,10 +75,11 @@ struct sap_handler_t ...@@ -75,10 +75,11 @@ struct sap_handler_t
{ {
VLC_COMMON_MEMBERS VLC_COMMON_MEMBERS
vlc_mutex_t lock;
sap_address_t *first; sap_address_t *first;
}; };
static vlc_mutex_t sap_mutex = VLC_STATIC_MUTEX;
#define SAP_MAX_BUFFER 65534 #define SAP_MAX_BUFFER 65534
#define MIN_INTERVAL 2 #define MIN_INTERVAL 2
#define MAX_INTERVAL 300 #define MAX_INTERVAL 300
...@@ -99,7 +100,6 @@ static sap_handler_t *SAP_Create (vlc_object_t *p_announce) ...@@ -99,7 +100,6 @@ static sap_handler_t *SAP_Create (vlc_object_t *p_announce)
if (p_sap == NULL) if (p_sap == NULL)
return NULL; return NULL;
vlc_mutex_init (&p_sap->lock);
p_sap->first = NULL; p_sap->first = NULL;
return p_sap; return p_sap;
} }
...@@ -107,7 +107,6 @@ static sap_handler_t *SAP_Create (vlc_object_t *p_announce) ...@@ -107,7 +107,6 @@ static sap_handler_t *SAP_Create (vlc_object_t *p_announce)
static void SAP_Destroy (sap_handler_t *p_sap) static void SAP_Destroy (sap_handler_t *p_sap)
{ {
assert (p_sap->first == NULL); assert (p_sap->first == NULL);
vlc_mutex_destroy (&p_sap->lock);
vlc_object_release (p_sap); vlc_object_release (p_sap);
} }
...@@ -299,7 +298,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap, ...@@ -299,7 +298,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap,
/* Find/create SAP address thread */ /* Find/create SAP address thread */
msg_Dbg( p_sap, "using SAP address: %s", psz_addr); 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; sap_address_t *sap_addr;
for (sap_addr = p_sap->first; sap_addr; sap_addr = sap_addr->next) for (sap_addr = p_sap->first; sap_addr; sap_addr = sap_addr->next)
if (!strcmp (psz_addr, sap_addr->group)) if (!strcmp (psz_addr, sap_addr->group))
...@@ -310,7 +309,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap, ...@@ -310,7 +309,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap,
sap_addr = AddressCreate (VLC_OBJECT(p_sap), psz_addr); sap_addr = AddressCreate (VLC_OBJECT(p_sap), psz_addr);
if (sap_addr == NULL) if (sap_addr == NULL)
{ {
vlc_mutex_unlock (&p_sap->lock); vlc_mutex_unlock (&sap_mutex);
return NULL; return NULL;
} }
sap_addr->next = p_sap->first; sap_addr->next = p_sap->first;
...@@ -319,7 +318,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap, ...@@ -319,7 +318,7 @@ static session_descriptor_t *SAP_Add (sap_handler_t *p_sap,
/* Switch locks. /* Switch locks.
* NEVER take the global SAP lock when holding a SAP thread lock! */ * NEVER take the global SAP lock when holding a SAP thread lock! */
vlc_mutex_lock (&sap_addr->lock); vlc_mutex_lock (&sap_addr->lock);
vlc_mutex_unlock (&p_sap->lock); vlc_mutex_unlock (&sap_mutex);
size_t length = 20; size_t length = 20;
switch (sap_addr->orig.ss_family) switch (sap_addr->orig.ss_family)
...@@ -402,7 +401,7 @@ static void SAP_Del (sap_handler_t *p_sap, session_descriptor_t *session) ...@@ -402,7 +401,7 @@ static void SAP_Del (sap_handler_t *p_sap, session_descriptor_t *session)
sap_address_t *addr, **paddr; sap_address_t *addr, **paddr;
session_descriptor_t **psession; session_descriptor_t **psession;
vlc_mutex_lock (&p_sap->lock); vlc_mutex_lock (&sap_mutex);
paddr = &p_sap->first; paddr = &p_sap->first;
for (;;) for (;;)
{ {
...@@ -427,7 +426,7 @@ found: ...@@ -427,7 +426,7 @@ found:
if (addr->first == NULL) if (addr->first == NULL)
/* Last session for this address -> unlink the address */ /* Last session for this address -> unlink the address */
*paddr = addr->next; *paddr = addr->next;
vlc_mutex_unlock (&p_sap->lock); vlc_mutex_unlock (&sap_mutex);
if (addr->first == NULL) if (addr->first == NULL)
{ {
...@@ -456,8 +455,6 @@ static void sap_destroy (vlc_object_t *p_this) ...@@ -456,8 +455,6 @@ static void sap_destroy (vlc_object_t *p_this)
#undef sout_AnnounceRegisterSDP #undef sout_AnnounceRegisterSDP
static vlc_mutex_t sap_mutex = VLC_STATIC_MUTEX;
/** /**
* Registers a new session with the announce handler, using a pregenerated SDP * Registers a new session with the announce handler, using a pregenerated SDP
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment