Use atomic operation functions for use/ringing/hold manipulation.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@52240 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
b8d6cbcd3f
commit
300f980223
1 changed files with 20 additions and 28 deletions
|
@ -3126,6 +3126,7 @@ static int update_call_counter(struct sip_pvt *fup, int event)
|
||||||
|
|
||||||
if (option_debug > 2)
|
if (option_debug > 2)
|
||||||
ast_log(LOG_DEBUG, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming");
|
ast_log(LOG_DEBUG, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming");
|
||||||
|
|
||||||
/* Test if we need to check call limits, in order to avoid
|
/* Test if we need to check call limits, in order to avoid
|
||||||
realtime lookups if we do not need it */
|
realtime lookups if we do not need it */
|
||||||
if (!ast_test_flag(&fup->flags[0], SIP_CALL_LIMIT))
|
if (!ast_test_flag(&fup->flags[0], SIP_CALL_LIMIT))
|
||||||
|
@ -3153,30 +3154,26 @@ static int update_call_counter(struct sip_pvt *fup, int event)
|
||||||
switch(event) {
|
switch(event) {
|
||||||
/* incoming and outgoing affects the inUse counter */
|
/* incoming and outgoing affects the inUse counter */
|
||||||
case DEC_CALL_LIMIT:
|
case DEC_CALL_LIMIT:
|
||||||
if ( *inuse > 0 ) {
|
/* Decrement inuse count if applicable */
|
||||||
if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT))
|
if (inuse && ast_test_flag(&fup->flags[0], SIP_INC_COUNT))
|
||||||
(*inuse)--;
|
ast_atomic_fetchadd_int(inuse, -1);
|
||||||
} else {
|
else
|
||||||
*inuse = 0;
|
*inuse = 0;
|
||||||
|
/* Decrement ringing count if applicable */
|
||||||
|
if (inringing && ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
|
||||||
|
ast_atomic_fetchadd_int(inringing, -1);
|
||||||
|
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
|
||||||
}
|
}
|
||||||
if (inringing) {
|
/* Decrement onhold count if applicable */
|
||||||
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
|
|
||||||
if (*inringing > 0)
|
|
||||||
(*inringing)--;
|
|
||||||
else
|
|
||||||
ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername);
|
|
||||||
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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)
|
||||||
sip_peer_hold(fup, 0);
|
sip_peer_hold(fup, FALSE);
|
||||||
if (option_debug > 1 || sipdebug) {
|
if (option_debug > 1 || sipdebug)
|
||||||
ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
|
ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INC_CALL_RINGING:
|
case INC_CALL_RINGING:
|
||||||
case INC_CALL_LIMIT:
|
case INC_CALL_LIMIT:
|
||||||
|
/* If call limit is active and we have reached the limit, reject the call */
|
||||||
if (*call_limit > 0 ) {
|
if (*call_limit > 0 ) {
|
||||||
if (*inuse >= *call_limit) {
|
if (*inuse >= *call_limit) {
|
||||||
ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
|
ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
|
||||||
|
@ -3189,12 +3186,12 @@ static int update_call_counter(struct sip_pvt *fup, int event)
|
||||||
}
|
}
|
||||||
if (inringing && (event == INC_CALL_RINGING)) {
|
if (inringing && (event == INC_CALL_RINGING)) {
|
||||||
if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
|
if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
|
||||||
(*inringing)++;
|
ast_atomic_fetchadd_int(inringing, +1);
|
||||||
ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
|
ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Continue */
|
/* Continue */
|
||||||
(*inuse)++;
|
ast_atomic_fetchadd_int(inuse, +1);
|
||||||
ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
|
ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
|
||||||
if (option_debug > 1 || sipdebug) {
|
if (option_debug > 1 || sipdebug) {
|
||||||
ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
|
ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
|
||||||
|
@ -3202,14 +3199,9 @@ static int update_call_counter(struct sip_pvt *fup, int event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEC_CALL_RINGING:
|
case DEC_CALL_RINGING:
|
||||||
if (inringing) {
|
if (inringing && ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
|
||||||
if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
|
ast_atomic_fetchadd_int(inringing, -1);
|
||||||
if (*inringing > 0)
|
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
|
||||||
(*inringing)--;
|
|
||||||
else
|
|
||||||
ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", p->name);
|
|
||||||
ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -8227,9 +8219,9 @@ static void sip_peer_hold(struct sip_pvt *p, int hold)
|
||||||
|
|
||||||
/* If they put someone on hold, increment the value... otherwise decrement it */
|
/* If they put someone on hold, increment the value... otherwise decrement it */
|
||||||
if (hold)
|
if (hold)
|
||||||
peer->onHold++;
|
ast_atomic_fetchadd_int(&peer->onHold, +1);
|
||||||
else
|
else
|
||||||
peer->onHold--;
|
ast_atomic_fetchadd_int(&peer->onHold, -1);
|
||||||
|
|
||||||
/* Request device state update */
|
/* Request device state update */
|
||||||
ast_device_state_changed("SIP/%s", peer->name);
|
ast_device_state_changed("SIP/%s", peer->name);
|
||||||
|
|
Loading…
Reference in a new issue