[asterisk-commits] russell: branch 1.4 r80895 - /branches/1.4/channels/chan_iax2.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Aug 25 12:37:40 CDT 2007
Author: russell
Date: Sat Aug 25 12:37:39 2007
New Revision: 80895
URL: http://svn.digium.com/view/asterisk?view=rev&rev=80895
Log:
Fix some issues with the handling of the scheduler in chan_iax2. Most of the
places that scheduled items to be executed by the scheduler thread did not
signal the scheduler thread to wake up so that it could recalculate the time
until the next action. These changes will make the scheduler thread more
responsive and ensure that actions get executed as close to when intended as
possible instead of it being possible for very long delays.
Modified:
branches/1.4/channels/chan_iax2.c
Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?view=diff&rev=80895&r1=80894&r2=80895
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Sat Aug 25 12:37:39 2007
@@ -963,6 +963,16 @@
#define schedule_action(func, data) __schedule_action(func, data, __PRETTY_FUNCTION__)
#endif
+static int iax2_sched_add(struct sched_context *con, int when, ast_sched_cb callback, void *data)
+{
+ int res;
+
+ res = ast_sched_add(con, when, callback, data);
+ signal_condition(&sched_lock, &sched_cond);
+
+ return res;
+}
+
static int send_ping(void *data);
static void __send_ping(void *data)
@@ -971,7 +981,7 @@
ast_mutex_lock(&iaxsl[callno]);
if (iaxs[callno] && iaxs[callno]->pingid != -1) {
send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_PING, 0, NULL, 0, -1);
- iaxs[callno]->pingid = ast_sched_add(sched, ping_time * 1000, send_ping, data);
+ iaxs[callno]->pingid = iax2_sched_add(sched, ping_time * 1000, send_ping, data);
}
ast_mutex_unlock(&iaxsl[callno]);
}
@@ -1006,7 +1016,7 @@
ast_mutex_lock(&iaxsl[callno]);
if (iaxs[callno] && iaxs[callno]->lagid != -1) {
send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_LAGRQ, 0, NULL, 0, -1);
- iaxs[callno]->lagid = ast_sched_add(sched, lagrq_time * 1000, send_lagrq, data);
+ iaxs[callno]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, data);
}
ast_mutex_unlock(&iaxsl[callno]);
}
@@ -1299,8 +1309,8 @@
ast_sched_del(sched, iaxs[x]->pingid);
if (iaxs[x]->lagid > -1)
ast_sched_del(sched, iaxs[x]->lagid);
- iaxs[x]->pingid = ast_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
- iaxs[x]->lagid = ast_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
+ iaxs[x]->pingid = iax2_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
+ iaxs[x]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
if (locked)
ast_mutex_unlock(&iaxsl[callno]);
res = x;
@@ -1388,8 +1398,8 @@
iaxs[x]->callno = x;
iaxs[x]->pingtime = DEFAULT_RETRY_TIME;
iaxs[x]->expiry = min_reg_expire;
- iaxs[x]->pingid = ast_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
- iaxs[x]->lagid = ast_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
+ iaxs[x]->pingid = iax2_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
+ iaxs[x]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
iaxs[x]->amaflags = amaflags;
ast_copy_flags(iaxs[x], (&globalflags), IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
@@ -2080,7 +2090,7 @@
/* Transfer messages max out at one second */
if (f->transfer && (f->retrytime > 1000))
f->retrytime = 1000;
- f->retrans = ast_sched_add(sched, f->retrytime, attempt_transmit, f);
+ f->retrans = iax2_sched_add(sched, f->retrytime, attempt_transmit, f);
}
} else {
/* Make sure it gets freed */
@@ -2415,10 +2425,7 @@
when = 1;
}
- pvt->jbid = ast_sched_add(sched, when, get_from_jb, CALLNO_TO_PTR(pvt->callno));
-
- /* Signal scheduler thread */
- signal_condition(&sched_lock, &sched_cond);
+ pvt->jbid = iax2_sched_add(sched, when, get_from_jb, CALLNO_TO_PTR(pvt->callno));
}
static void __get_from_jb(void *p)
@@ -2722,7 +2729,7 @@
if (ast_test_flag(peer, IAX_RTAUTOCLEAR)) {
if (peer->expire > -1)
ast_sched_del(sched, peer->expire);
- peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, (void*)peer->name);
+ peer->expire = iax2_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, (void*)peer->name);
}
ao2_link(peers, peer_ref(peer));
if (ast_test_flag(peer, IAX_DYNAMIC))
@@ -3137,10 +3144,10 @@
if (iaxs[callno]->maxtime) {
/* Initialize pingtime and auto-congest time */
iaxs[callno]->pingtime = iaxs[callno]->maxtime / 2;
- iaxs[callno]->initid = ast_sched_add(sched, iaxs[callno]->maxtime * 2, auto_congest, CALLNO_TO_PTR(callno));
+ iaxs[callno]->initid = iax2_sched_add(sched, iaxs[callno]->maxtime * 2, auto_congest, CALLNO_TO_PTR(callno));
} else if (autokill) {
iaxs[callno]->pingtime = autokill / 2;
- iaxs[callno]->initid = ast_sched_add(sched, autokill * 2, auto_congest, CALLNO_TO_PTR(callno));
+ iaxs[callno]->initid = iax2_sched_add(sched, autokill * 2, auto_congest, CALLNO_TO_PTR(callno));
}
/* send the command using the appropriate socket for this peer */
@@ -5664,7 +5671,7 @@
reg->refresh = refresh;
if (reg->expire > -1)
ast_sched_del(sched, reg->expire);
- reg->expire = ast_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
+ reg->expire = iax2_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
if (inaddrcmp(&oldus, ®->us) || (reg->messages != oldmsgs)) {
if (option_verbose > 2) {
if (reg->messages > 255)
@@ -5825,7 +5832,7 @@
if (p->expire > -1)
ast_sched_del(sched, p->expire);
ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
- p->expire = ast_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, (void *)p->name);
+ p->expire = iax2_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, (void *)p->name);
if (iax2_regfunk)
iax2_regfunk(p->name, 1);
register_peer_exten(p, 1);
@@ -5931,7 +5938,7 @@
p->expiry = refresh;
}
if (p->expiry && sin->sin_addr.s_addr)
- p->expire = ast_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, (void *)p->name);
+ p->expire = iax2_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, (void *)p->name);
iax_ie_append_str(&ied, IAX_IE_USERNAME, p->name);
iax_ie_append_int(&ied, IAX_IE_DATETIME, iax2_datetime(p->zonetag));
if (sin->sin_addr.s_addr) {
@@ -6098,7 +6105,7 @@
if (delayreject) {
if (iaxs[callno]->authid > -1)
ast_sched_del(sched, iaxs[callno]->authid);
- iaxs[callno]->authid = ast_sched_add(sched, 1000, auth_reject, (void *)(long)callno);
+ iaxs[callno]->authid = iax2_sched_add(sched, 1000, auth_reject, (void *)(long)callno);
} else
auth_reject((void *)(long)callno);
}
@@ -6141,7 +6148,7 @@
/* Auto-hangup with 30 seconds of inactivity */
if (iaxs[callno]->autoid > -1)
ast_sched_del(sched, iaxs[callno]->autoid);
- iaxs[callno]->autoid = ast_sched_add(sched, 30000, auto_hangup, (void *)(long)callno);
+ iaxs[callno]->autoid = iax2_sched_add(sched, 30000, auto_hangup, (void *)(long)callno);
memset(&ied, 0, sizeof(ied));
iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, dp->exten);
send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_DPREQ, 0, ied.buf, ied.pos, -1);
@@ -7589,9 +7596,9 @@
ast_sched_del(sched, peer->pokeexpire);
/* Schedule the next cycle */
if ((peer->lastms < 0) || (peer->historicms > peer->maxms))
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
+ peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
else
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqok, iax2_poke_peer_s, peer);
+ peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqok, iax2_poke_peer_s, peer);
/* and finally send the ack */
send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
/* And wrap up the qualify call */
@@ -8300,7 +8307,7 @@
/* Setup the next registration attempt */
if (reg->expire > -1)
ast_sched_del(sched, reg->expire);
- reg->expire = ast_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
+ reg->expire = iax2_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
return -1;
}
@@ -8319,7 +8326,7 @@
if (reg->expire > -1)
ast_sched_del(sched, reg->expire);
/* Setup the next registration a little early */
- reg->expire = ast_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
+ reg->expire = iax2_sched_add(sched, (5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
/* Send the request */
memset(&ied, 0, sizeof(ied));
iax_ie_append_str(&ied, IAX_IE_USERNAME, reg->username);
@@ -8376,7 +8383,7 @@
/* Schedule autodestruct in case they don't ever give us anything back */
if (iaxs[callno]->autoid > -1)
ast_sched_del(sched, iaxs[callno]->autoid);
- iaxs[callno]->autoid = ast_sched_add(sched, 15000, auto_hangup, (void *)(long)callno);
+ iaxs[callno]->autoid = iax2_sched_add(sched, 15000, auto_hangup, (void *)(long)callno);
ast_set_flag(iaxs[callno], IAX_PROVISION);
/* Got a call number now, so go ahead and send the provisioning information */
send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_PROVISION, 0, ied.buf, ied.pos, -1);
@@ -8465,7 +8472,7 @@
peer->callno = 0;
peer->lastms = -1;
/* Try again quickly */
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
+ peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
}
static int iax2_poke_noanswer(void *data)
@@ -8526,9 +8533,9 @@
/* Queue up a new task to handle no reply */
/* If the host is already unreachable then use the unreachable interval instead */
if (peer->lastms < 0) {
- peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer);
+ peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer);
} else
- peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer);
+ peer->pokeexpire = iax2_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer);
/* And send the poke */
send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
@@ -8702,7 +8709,7 @@
} else {
/* We need reliable delivery. Schedule a retransmission */
f->retries++;
- f->retrans = ast_sched_add(sched, f->retrytime, attempt_transmit, f);
+ f->retrans = iax2_sched_add(sched, f->retrytime, attempt_transmit, f);
signal_condition(&sched_lock, &sched_cond);
}
}
More information about the asterisk-commits
mailing list