With the switch to the ast_sched_replace* API in trunk, we lose the correction

that was just merged from 1.4, so this is a changeover to those APIs to use the
macro versions, so that we properly detect errors from ast_sched_del, instead
of simply ignoring the return values.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@100497 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Tilghman Lesher 18 years ago
parent ac699196f5
commit 69ade72e3c

@ -1094,14 +1094,12 @@ static int __schedule_action(void (*func)(const void *data), const void *data, c
#define schedule_action(func, data) __schedule_action(func, data, __PRETTY_FUNCTION__) #define schedule_action(func, data) __schedule_action(func, data, __PRETTY_FUNCTION__)
#endif #endif
static int iax2_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) static int iax2_sched_replace(int id, struct sched_context *con, int when, ast_sched_cb callback, const void *data)
{ {
int res; AST_SCHED_REPLACE(id, con, when, callback, data);
res = ast_sched_replace(old_id, con, when, callback, data);
signal_condition(&sched_lock, &sched_cond); signal_condition(&sched_lock, &sched_cond);
return res; return id;
} }
static int iax2_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) static int iax2_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data)

@ -2810,8 +2810,7 @@ static enum sip_result __sip_reliable_xmit(struct sip_pvt *p, int seqno, int res
siptimer_a = pkt->timer_t1 * 2; siptimer_a = pkt->timer_t1 * 2;
/* Schedule retransmission */ /* Schedule retransmission */
pkt->retransid = ast_sched_replace_variable(pkt->retransid, sched, AST_SCHED_REPLACE_VARIABLE(pkt->retransid, sched, siptimer_a, retrans_pkt, pkt, 1);
siptimer_a, retrans_pkt, pkt, 1);
if (sipdebug) if (sipdebug)
ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid); ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid);
@ -3627,8 +3626,7 @@ static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_i
/* Cache peer */ /* Cache peer */
ast_copy_flags(&peer->flags[1],&global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS); ast_copy_flags(&peer->flags[1],&global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) { if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
peer->expire = ast_sched_replace(peer->expire, sched, AST_SCHED_REPLACE(peer->expire, sched, global_rtautoclear * 1000, expire_register, (void *) peer);
global_rtautoclear * 1000, expire_register, (void *) peer);
} }
ASTOBJ_CONTAINER_LINK(&peerl,peer); ASTOBJ_CONTAINER_LINK(&peerl,peer);
} else { } else {
@ -4085,8 +4083,7 @@ static int sip_call(struct ast_channel *ast, char *dest, int timeout)
p->invitestate = INV_CALLING; p->invitestate = INV_CALLING;
/* Initialize auto-congest time */ /* Initialize auto-congest time */
p->initid = ast_sched_replace(p->initid, sched, p->timer_b, AST_SCHED_REPLACE(p->initid, sched, p->timer_b, auto_congest, dialog_ref(p));
auto_congest, dialog_ref(p));
} }
return res; return res;
@ -8979,8 +8976,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
* probably DNS. We need to reschedule a registration try */ * probably DNS. We need to reschedule a registration try */
sip_destroy(p); sip_destroy(p);
if (r->timeout > -1) { if (r->timeout > -1) {
r->timeout = ast_sched_replace(r->timeout, sched, AST_SCHED_REPLACE(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
global_reg_timeout * 1000, sip_reg_timeout, r);
ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout); ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
} else { } else {
r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r); r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r);
@ -9035,7 +9031,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
if (auth == NULL) { if (auth == NULL) {
if (r->timeout > -1) if (r->timeout > -1)
ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout); ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout);
r->timeout = ast_sched_replace(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r); AST_SCHED_REPLACE(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
ast_debug(1, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout); ast_debug(1, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout);
} }
@ -9414,12 +9410,10 @@ static void reg_source_db(struct sip_peer *peer)
peer->addr.sin_port = htons(port); peer->addr.sin_port = htons(port);
if (sipsock < 0) { if (sipsock < 0) {
/* SIP isn't up yet, so schedule a poke only, pretty soon */ /* SIP isn't up yet, so schedule a poke only, pretty soon */
peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, AST_SCHED_REPLACE(peer->pokeexpire, sched, ast_random() % 5000 + 1, sip_poke_peer_s, peer);
ast_random() % 5000 + 1, sip_poke_peer_s, peer);
} else } else
sip_poke_peer(peer); sip_poke_peer(peer);
peer->expire = ast_sched_replace(peer->expire, sched, AST_SCHED_REPLACE(peer->expire, sched, (expiry + 10) * 1000, expire_register, peer);
(expiry + 10) * 1000, expire_register, peer);
register_peer_exten(peer, TRUE); register_peer_exten(peer, TRUE);
} }
@ -14776,7 +14770,7 @@ static int handle_response_register(struct sip_pvt *p, int resp, char *rest, str
r->refresh= (int) expires_ms / 1000; r->refresh= (int) expires_ms / 1000;
/* Schedule re-registration before we expire */ /* Schedule re-registration before we expire */
r->expire = ast_sched_replace(r->expire, sched, expires_ms, sip_reregister, r); AST_SCHED_REPLACE(r->expire, sched, expires_ms, sip_reregister, r);
registry_unref(r); registry_unref(r);
} }
return 1; return 1;
@ -14824,7 +14818,7 @@ static void handle_response_peerpoke(struct sip_pvt *p, int resp, struct sip_req
p->needdestroy = 1; p->needdestroy = 1;
/* Try again eventually */ /* Try again eventually */
peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, AST_SCHED_REPLACE(peer->pokeexpire, sched,
is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK, is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK,
sip_poke_peer_s, peer); sip_poke_peer_s, peer);
} }
@ -18545,7 +18539,7 @@ static int sip_poke_noanswer(const void *data)
peer->lastms = -1; peer->lastms = -1;
ast_device_state_changed("SIP/%s", peer->name); ast_device_state_changed("SIP/%s", peer->name);
/* Try again quickly */ /* Try again quickly */
peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, AST_SCHED_REPLACE(peer->pokeexpire, sched,
DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer); DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
return 0; return 0;
} }
@ -18607,7 +18601,7 @@ static int sip_poke_peer(struct sip_peer *peer)
if (xmitres == XMIT_ERROR) if (xmitres == XMIT_ERROR)
sip_poke_noanswer(peer); /* Immediately unreachable, network problems */ sip_poke_noanswer(peer); /* Immediately unreachable, network problems */
else { else {
peer->pokeexpire = ast_sched_replace(peer->pokeexpire, sched, AST_SCHED_REPLACE(peer->pokeexpire, sched,
peer->maxms * 2, sip_poke_noanswer, peer); peer->maxms * 2, sip_poke_noanswer, peer);
} }
@ -20964,8 +20958,7 @@ static void sip_poke_all_peers(void)
ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do { ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
ASTOBJ_WRLOCK(iterator); ASTOBJ_WRLOCK(iterator);
ms += 100; ms += 100;
iterator->pokeexpire = ast_sched_replace(iterator->pokeexpire, AST_SCHED_REPLACE(iterator->pokeexpire, sched, ms, sip_poke_peer_s, iterator);
sched, ms, sip_poke_peer_s, iterator);
ASTOBJ_UNLOCK(iterator); ASTOBJ_UNLOCK(iterator);
} while (0) } while (0)
); );
@ -20985,7 +20978,7 @@ static void sip_send_all_registers(void)
ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do { ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
ASTOBJ_WRLOCK(iterator); ASTOBJ_WRLOCK(iterator);
ms += regspacing; ms += regspacing;
iterator->expire = ast_sched_replace(iterator->expire, AST_SCHED_REPLACE(iterator->expire,
sched, ms, sip_reregister, iterator); sched, ms, sip_reregister, iterator);
ASTOBJ_UNLOCK(iterator); ASTOBJ_UNLOCK(iterator);
} while (0) } while (0)

@ -45,6 +45,19 @@ extern "C" {
id = -1; \ id = -1; \
} while (0); } while (0);
#define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \
do { \
int _count = 0; \
while (id > -1 && ast_sched_del(sched, id) && _count++ < 10) \
usleep(1); \
if (_count == 10) \
ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
id = ast_sched_add_variable(sched, when, callback, data, variable); \
} while (0);
#define AST_SCHED_REPLACE(id, sched, when, callback, data) \
AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0)
struct sched_context; struct sched_context;
/*! \brief New schedule context /*! \brief New schedule context

Loading…
Cancel
Save