merge rev.47224 from team/rizzo/astobj2:

hide dialoglist lock/unlocking in wrapper functions.

Approved By: oej



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47315 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Luigi Rizzo 19 years ago
parent f58302fc9c
commit 24dfbe955e

@ -559,9 +559,6 @@ static int regobjs = 0; /*!< Registry objects */
static struct ast_flags global_flags[2] = {{0}}; /*!< global SIP_ flags */ static struct ast_flags global_flags[2] = {{0}}; /*!< global SIP_ flags */
/*! \brief Protect the SIP dialog list (of sip_pvt's) */
AST_MUTEX_DEFINE_STATIC(dialoglock);
AST_MUTEX_DEFINE_STATIC(netlock); AST_MUTEX_DEFINE_STATIC(netlock);
/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
@ -995,6 +992,20 @@ struct sip_pvt {
static struct sip_pvt *dialoglist = NULL; static struct sip_pvt *dialoglist = NULL;
/*! \brief Protect the SIP dialog list (of sip_pvt's) */
AST_MUTEX_DEFINE_STATIC(dialoglock);
/*! \brief hide the way the list is locked/unlocked */
static void dialoglist_lock(void)
{
ast_mutex_lock(&dialoglock);
}
static void dialoglist_unlock(void)
{
ast_mutex_unlock(&dialoglock);
}
#define FLAG_RESPONSE (1 << 0) #define FLAG_RESPONSE (1 << 0)
#define FLAG_FATAL (1 << 1) #define FLAG_FATAL (1 << 1)
@ -2981,7 +2992,7 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist)
/* Lock dialog list before removing ourselves from the list */ /* Lock dialog list before removing ourselves from the list */
if (lockdialoglist) if (lockdialoglist)
ast_mutex_lock(&dialoglock); dialoglist_lock();
for (prev = NULL, cur = dialoglist; cur; prev = cur, cur = cur->next) { for (prev = NULL, cur = dialoglist; cur; prev = cur, cur = cur->next) {
if (cur == p) { if (cur == p) {
UNLINK(cur, dialoglist, prev); UNLINK(cur, dialoglist, prev);
@ -2989,7 +3000,7 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist)
} }
} }
if (lockdialoglist) if (lockdialoglist)
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
if (!cur) { if (!cur) {
ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid); ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid);
return; return;
@ -4297,10 +4308,10 @@ static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *si
ast_string_field_set(p, context, default_context); ast_string_field_set(p, context, default_context);
/* Add to active dialog list */ /* Add to active dialog list */
ast_mutex_lock(&dialoglock); dialoglist_lock();
p->next = dialoglist; p->next = dialoglist;
dialoglist = p; dialoglist = p;
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP"); ast_log(LOG_DEBUG, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
return p; return p;
@ -4342,7 +4353,7 @@ static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *si
ast_log(LOG_DEBUG, "= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag); ast_log(LOG_DEBUG, "= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
} }
ast_mutex_lock(&dialoglock); dialoglist_lock();
for (p = dialoglist; p; p = p->next) { for (p = dialoglist; p; p = p->next) {
/* In pedantic, we do not want packets with bad syntax to be connected to a PVT */ /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
int found = FALSE; int found = FALSE;
@ -4373,11 +4384,11 @@ static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *si
if (found) { if (found) {
/* Found the call */ /* Found the call */
sip_pvt_lock(p); sip_pvt_lock(p);
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
return p; return p;
} }
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
/* See if the method is capable of creating a dialog */ /* See if the method is capable of creating a dialog */
if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) { if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {
@ -8506,7 +8517,7 @@ static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *t
{ {
struct sip_pvt *sip_pvt_ptr; struct sip_pvt *sip_pvt_ptr;
ast_mutex_lock(&dialoglock); dialoglist_lock();
if (option_debug > 3 && totag) if (option_debug > 3 && totag)
ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>"); ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
@ -8546,7 +8557,7 @@ static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *t
break; break;
} }
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
if (option_debug > 3 && !sip_pvt_ptr) if (option_debug > 3 && !sip_pvt_ptr)
ast_log(LOG_DEBUG, "Found no match for callid %s to-tag %s from-tag %s\n", callid, totag, fromtag); ast_log(LOG_DEBUG, "Found no match for callid %s to-tag %s from-tag %s\n", callid, totag, fromtag);
return sip_pvt_ptr; return sip_pvt_ptr;
@ -10415,7 +10426,7 @@ static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
ast_mutex_lock(&dialoglock); dialoglist_lock();
cur = dialoglist; cur = dialoglist;
if (!subscriptions) if (!subscriptions)
ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message"); ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
@ -10452,7 +10463,7 @@ static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions
numchans++; numchans++;
} }
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
if (!subscriptions) if (!subscriptions)
ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : ""); ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : "");
else else
@ -10471,14 +10482,14 @@ static char *complete_sipch(const char *line, const char *word, int pos, int sta
char *c = NULL; char *c = NULL;
int wordlen = strlen(word); int wordlen = strlen(word);
ast_mutex_lock(&dialoglock); dialoglist_lock();
for (cur = dialoglist; cur; cur = cur->next) { for (cur = dialoglist; cur; cur = cur->next) {
if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) { if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) {
c = ast_strdup(cur->callid); c = ast_strdup(cur->callid);
break; break;
} }
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
return c; return c;
} }
@ -10603,7 +10614,7 @@ static int sip_show_channel(int fd, int argc, char *argv[])
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
len = strlen(argv[3]); len = strlen(argv[3]);
ast_mutex_lock(&dialoglock); dialoglist_lock();
for (cur = dialoglist; cur; cur = cur->next) { for (cur = dialoglist; cur; cur = cur->next) {
if (!strncasecmp(cur->callid, argv[3], len)) { if (!strncasecmp(cur->callid, argv[3], len)) {
char formatbuf[BUFSIZ/2]; char formatbuf[BUFSIZ/2];
@ -10657,7 +10668,7 @@ static int sip_show_channel(int fd, int argc, char *argv[])
found++; found++;
} }
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
if (!found) if (!found)
ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
return RESULT_SUCCESS; return RESULT_SUCCESS;
@ -10675,7 +10686,7 @@ static int sip_show_history(int fd, int argc, char *argv[])
if (!recordhistory) if (!recordhistory)
ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n"); ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n");
len = strlen(argv[3]); len = strlen(argv[3]);
ast_mutex_lock(&dialoglock); dialoglist_lock();
for (cur = dialoglist; cur; cur = cur->next) { for (cur = dialoglist; cur; cur = cur->next) {
if (!strncasecmp(cur->callid, argv[3], len)) { if (!strncasecmp(cur->callid, argv[3], len)) {
struct sip_history *hist; struct sip_history *hist;
@ -10694,7 +10705,7 @@ static int sip_show_history(int fd, int argc, char *argv[])
found++; found++;
} }
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
if (!found) if (!found)
ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
return RESULT_SUCCESS; return RESULT_SUCCESS;
@ -14319,7 +14330,7 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req,
for it to expire and send NOTIFY messages to the peer only to have them for it to expire and send NOTIFY messages to the peer only to have them
ignored (or generate errors) ignored (or generate errors)
*/ */
ast_mutex_lock(&dialoglock); dialoglist_lock();
for (p_old = dialoglist; p_old; p_old = p_old->next) { for (p_old = dialoglist; p_old; p_old = p_old->next) {
if (p_old == p) if (p_old == p)
continue; continue;
@ -14338,7 +14349,7 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req,
} }
sip_pvt_unlock(p_old); sip_pvt_unlock(p_old);
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
} }
if (!p->expiry) if (!p->expiry)
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
@ -14848,7 +14859,7 @@ static void *do_monitor(void *data)
sipsock_read_id = ast_io_change(io, sipsock_read_id, sipsock, NULL, 0, NULL); sipsock_read_id = ast_io_change(io, sipsock_read_id, sipsock, NULL, 0, NULL);
} }
/* Check for dialogs needing to be killed */ /* Check for dialogs needing to be killed */
ast_mutex_lock(&dialoglock); dialoglist_lock();
restartsearch: restartsearch:
t = time(NULL); t = time(NULL);
/* don't scan the dialogs list if it hasn't been a reasonable period /* don't scan the dialogs list if it hasn't been a reasonable period
@ -14868,7 +14879,7 @@ restartsearch:
} }
sip_pvt_unlock(sip); sip_pvt_unlock(sip);
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
pthread_testcancel(); pthread_testcancel();
/* Wait for sched or io */ /* Wait for sched or io */
@ -17193,13 +17204,13 @@ static int unload_module(void)
ast_manager_unregister("SIPpeers"); ast_manager_unregister("SIPpeers");
ast_manager_unregister("SIPshowpeer"); ast_manager_unregister("SIPshowpeer");
ast_mutex_lock(&dialoglock); dialoglist_lock();
/* Hangup all dialogs if they have an owner */ /* Hangup all dialogs if they have an owner */
for (p = dialoglist; p ; p = p->next) { for (p = dialoglist; p ; p = p->next) {
if (p->owner) if (p->owner)
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
} }
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
ast_mutex_lock(&monlock); ast_mutex_lock(&monlock);
if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) { if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
@ -17210,7 +17221,7 @@ static int unload_module(void)
monitor_thread = AST_PTHREADT_STOP; monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock); ast_mutex_unlock(&monlock);
ast_mutex_lock(&dialoglock); dialoglist_lock();
/* Destroy all the dialogs and free their memory */ /* Destroy all the dialogs and free their memory */
p = dialoglist; p = dialoglist;
while (p) { while (p) {
@ -17219,7 +17230,7 @@ static int unload_module(void)
__sip_destroy(pl, TRUE, TRUE); __sip_destroy(pl, TRUE, TRUE);
} }
dialoglist = NULL; dialoglist = NULL;
ast_mutex_unlock(&dialoglock); dialoglist_unlock();
/* Free memory for local network address mask */ /* Free memory for local network address mask */
ast_free_ha(localaddr); ast_free_ha(localaddr);

Loading…
Cancel
Save