mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
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. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@80895 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -963,6 +963,16 @@ static int __schedule_action(void (*func)(void *data), void *data, const char *f
|
||||
#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 @@ static void __send_ping(void *data)
|
||||
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 @@ static void __send_lagrq(void *data)
|
||||
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 @@ static int make_trunk(unsigned short callno, int locked)
|
||||
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 @@ static int find_callno(unsigned short callno, unsigned short dcallno, struct soc
|
||||
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 @@ static void __attempt_transmit(void *data)
|
||||
/* 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 @@ static void update_jbsched(struct chan_iax2_pvt *pvt)
|
||||
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 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
|
||||
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 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
|
||||
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 @@ static int iax2_ack_registry(struct iax_ies *ies, struct sockaddr_in *sin, int c
|
||||
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 @@ static void reg_source_db(struct iax2_peer *p)
|
||||
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 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
|
||||
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 @@ static int auth_fail(int callno, int failcode)
|
||||
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 @@ static void iax2_dprequest(struct iax2_dpcache *dp, int callno)
|
||||
/* 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 @@ retryowner2:
|
||||
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 @@ static int iax2_do_register(struct iax2_registry *reg)
|
||||
/* 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 @@ static int iax2_do_register(struct iax2_registry *reg)
|
||||
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 @@ static int iax2_provision(struct sockaddr_in *end, int sockfd, char *dest, const
|
||||
/* 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 @@ static void __iax2_poke_noanswer(void *data)
|
||||
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 @@ static int iax2_poke_peer(struct iax2_peer *peer, int heldcall)
|
||||
/* 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 @@ static void *network_thread(void *ignore)
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user