Based on Russell's advice on the asterisk-dev list, I have

changed from using a global lock in update_call_counter to
using the locks within the sip_pvt and sip_peer structures
instead.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@157496 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.2
Mark Michelson 17 years ago
parent 947429b2b3
commit 2ede9a603f

@ -2118,9 +2118,6 @@ enum t38_action_flag {
SDP_T38_ACCEPT, /*!< Remote side accepted our T38 request */ SDP_T38_ACCEPT, /*!< Remote side accepted our T38 request */
}; };
/*! \brief Protect the callcounters inuse,inringing and the corresponding flags */
AST_MUTEX_DEFINE_STATIC(callctrlock);
/*---------------------------- Forward declarations of functions in chan_sip.c */ /*---------------------------- Forward declarations of functions in chan_sip.c */
/* Note: This is added to help splitting up chan_sip.c into several files /* Note: This is added to help splitting up chan_sip.c into several files
in coming releases. */ in coming releases. */
@ -5099,36 +5096,43 @@ static int update_call_counter(struct sip_pvt *fup, int event)
case DEC_CALL_LIMIT: case DEC_CALL_LIMIT:
/* Decrement inuse count if applicable */ /* Decrement inuse count if applicable */
if (inuse) { if (inuse) {
ast_mutex_lock(&callctrlock); sip_pvt_lock(fup);
ao2_lock(p);
if ((*inuse > 0) && ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { if ((*inuse > 0) && ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
(*inuse)--; (*inuse)--;
ast_clear_flag(&fup->flags[0], SIP_INC_COUNT); ast_clear_flag(&fup->flags[0], SIP_INC_COUNT);
} else { } else {
*inuse = 0; *inuse = 0;
} }
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
} }
/* Decrement ringing count if applicable */ /* Decrement ringing count if applicable */
if (inringing) { if (inringing) {
ast_mutex_lock(&callctrlock); sip_pvt_lock(fup);
ao2_lock(p);
if ((*inringing > 0)&& ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { if ((*inringing > 0)&& ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
(*inringing)--; (*inringing)--;
ast_clear_flag(&fup->flags[0], SIP_INC_RINGING); ast_clear_flag(&fup->flags[0], SIP_INC_RINGING);
} else { } else {
*inringing = 0; *inringing = 0;
} }
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
} }
/* Decrement onhold count if applicable */ /* Decrement onhold count if applicable */
ast_mutex_lock(&callctrlock); sip_pvt_lock(fup);
ao2_lock(p);
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && global_notifyhold) { if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && global_notifyhold) {
ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD); ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD);
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
sip_peer_hold(fup, FALSE); sip_peer_hold(fup, FALSE);
} else { } else {
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
} }
if (sipdebug) if (sipdebug)
ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", "peer", name, *call_limit); ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", "peer", name, *call_limit);
@ -5145,20 +5149,24 @@ static int update_call_counter(struct sip_pvt *fup, int event)
} }
} }
if (inringing && (event == INC_CALL_RINGING)) { if (inringing && (event == INC_CALL_RINGING)) {
ast_mutex_lock(&callctrlock); sip_pvt_lock(fup);
ao2_lock(p);
if (!ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { if (!ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
(*inringing)++; (*inringing)++;
ast_set_flag(&fup->flags[0], SIP_INC_RINGING); ast_set_flag(&fup->flags[0], SIP_INC_RINGING);
} }
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
} }
if (inuse) { if (inuse) {
ast_mutex_lock(&callctrlock); sip_pvt_lock(fup);
ao2_lock(p);
if (!ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { if (!ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
(*inuse)++; (*inuse)++;
ast_set_flag(&fup->flags[0], SIP_INC_COUNT); ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
} }
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
} }
if (sipdebug) { if (sipdebug) {
ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", "peer", name, *inuse, *call_limit); ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", "peer", name, *inuse, *call_limit);
@ -5167,12 +5175,14 @@ static int update_call_counter(struct sip_pvt *fup, int event)
case DEC_CALL_RINGING: case DEC_CALL_RINGING:
if (inringing) { if (inringing) {
ast_mutex_lock(&callctrlock); sip_pvt_lock(fup);
ao2_lock(p);
if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
(*inringing)--; (*inringing)--;
ast_clear_flag(&fup->flags[0], SIP_INC_RINGING); ast_clear_flag(&fup->flags[0], SIP_INC_RINGING);
} }
ast_mutex_unlock(&callctrlock); ao2_unlock(p);
sip_pvt_unlock(fup);
} }
break; break;

Loading…
Cancel
Save