aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-18 20:29:18 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-18 20:29:18 +0000
commit9234b138bbd4b24a4542fc90db4a217b34ae920f (patch)
tree3a7bdacc452d015d50bbfe062cf3c2ef2903b8ff /channels
parent636c8a6a0a0d33a560d6200a0cbde96fe4776fb9 (diff)
Merged revisions 157427 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r157427 | mmichelson | 2008-11-18 14:23:58 -0600 (Tue, 18 Nov 2008) | 13 lines * Add a lock to be used in the update_call_counter function. * Revert logic to mirror 1.4's in the sense that it will not allow the call counter to dip below 0. These two measures prevent potential races that could cause a SIP peer to appear to be busy forever. (closes issue #13668) Reported by: mjc Patches: hintfix_trunk_rev152649.patch uploaded by wolfelectronic (license 586) ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@157428 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_sip.c64
1 files changed, 48 insertions, 16 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 69dfa7598..f05db15f7 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1691,6 +1691,9 @@ enum t38_action_flag {
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 */
/* Note: This is added to help splitting up chan_sip.c into several files
in coming releases. */
@@ -4508,7 +4511,7 @@ static int update_call_counter(struct sip_pvt *fup, int event)
call_limit = &p->call_limit;
inringing = &p->inRinging;
ast_copy_string(name, fup->peername, sizeof(name));
- }
+ }
if (!p && !u) {
ast_debug(2, "%s is not a local device, no call limit\n", name);
return 0;
@@ -4518,20 +4521,37 @@ static int update_call_counter(struct sip_pvt *fup, int event)
/* incoming and outgoing affects the inUse counter */
case DEC_CALL_LIMIT:
/* Decrement inuse count if applicable */
- if (inuse && *inuse > 0 && ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
- ast_atomic_fetchadd_int(inuse, -1);
- ast_clear_flag(&fup->flags[0], SIP_INC_COUNT);
- } else
- *inuse = 0;
+ if (inuse) {
+ ast_mutex_lock(&callctrlock);
+ if ((*inuse > 0) && ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
+ (*inuse)--;
+ ast_clear_flag(&fup->flags[0], SIP_INC_COUNT);
+ } else {
+ *inuse = 0;
+ }
+ ast_mutex_unlock(&callctrlock);
+ }
+
/* Decrement ringing count if applicable */
- if (inringing && *inringing > 0 && ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
- ast_atomic_fetchadd_int(inringing, -1);
- ast_clear_flag(&fup->flags[0], SIP_INC_RINGING);
+ if (inringing) {
+ ast_mutex_lock(&callctrlock);
+ if ((*inringing > 0)&& ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
+ (*inringing)--;
+ ast_clear_flag(&fup->flags[0], SIP_INC_RINGING);
+ } else {
+ *inringing = 0;
+ }
+ ast_mutex_unlock(&callctrlock);
}
+
/* Decrement onhold count if applicable */
+ ast_mutex_lock(&callctrlock);
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && global_notifyhold) {
ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD);
+ ast_mutex_unlock(&callctrlock);
sip_peer_hold(fup, FALSE);
+ } else {
+ ast_mutex_unlock(&callctrlock);
}
if (sipdebug)
ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
@@ -4551,29 +4571,41 @@ static int update_call_counter(struct sip_pvt *fup, int event)
}
}
if (inringing && (event == INC_CALL_RINGING)) {
+ ast_mutex_lock(&callctrlock);
if (!ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
- ast_atomic_fetchadd_int(inringing, +1);
+ (*inringing)++;
ast_set_flag(&fup->flags[0], SIP_INC_RINGING);
}
+ ast_mutex_unlock(&callctrlock);
+ }
+ if (inuse) {
+ ast_mutex_lock(&callctrlock);
+ if (!ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
+ (*inuse)++;
+ ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
+ }
+ ast_mutex_unlock(&callctrlock);
}
- /* Continue */
- ast_atomic_fetchadd_int(inuse, +1);
- ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
if (sipdebug) {
ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
}
break;
case DEC_CALL_RINGING:
- if (inringing && *inringing > 0 && ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
- ast_atomic_fetchadd_int(inringing, -1);
- ast_clear_flag(&fup->flags[0], SIP_INC_RINGING);
+ if (inringing) {
+ ast_mutex_lock(&callctrlock);
+ if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) {
+ (*inringing)--;
+ ast_clear_flag(&fup->flags[0], SIP_INC_RINGING);
+ }
+ ast_mutex_unlock(&callctrlock);
}
break;
default:
ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
}
+
if (p) {
ast_device_state_changed("SIP/%s", p->name);
unref_peer(p);