Optimized calls to pri_schedule_del().

There is no need to test if a scheduled event is running before calling
pri_schedule_del().


git-svn-id: https://origsvn.digium.com/svn/libpri/branches/1.4@1060 2fbb986a-6c06-0410-b554-c9c1f0a7f128
This commit is contained in:
Richard Mudgett 2009-09-02 20:04:03 +00:00
parent 6d5aeb7cdd
commit 6d9c1cb0d9
2 changed files with 24 additions and 47 deletions

16
q921.c
View File

@ -139,7 +139,6 @@ static void q921_tei_request(void *vpri)
#endif #endif
pri->ri = random() % 65535; pri->ri = random() % 65535;
q921_send_tei(pri, Q921_TEI_IDENTITY_REQUEST, pri->ri, Q921_TEI_GROUP, 1); q921_send_tei(pri, Q921_TEI_IDENTITY_REQUEST, pri->ri, Q921_TEI_GROUP, 1);
if (pri->t202_timer)
pri_schedule_del(pri, pri->t202_timer); pri_schedule_del(pri, pri->t202_timer);
pri->t202_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T202], q921_tei_request, pri); pri->t202_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T202], q921_tei_request, pri);
} }
@ -174,8 +173,8 @@ static void q921_send_sabme(void *vpri, int now)
{ {
struct pri *pri = vpri; struct pri *pri = vpri;
q921_h h; q921_h h;
pri_schedule_del(pri, pri->sabme_timer); pri_schedule_del(pri, pri->sabme_timer);
pri->sabme_timer = 0;
pri->sabme_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], q921_send_sabme_now, pri); pri->sabme_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], q921_send_sabme_now, pri);
if (!now) if (!now)
return; return;
@ -253,7 +252,6 @@ static void reschedule_t200(struct pri *pri)
{ {
if (pri->debug & PRI_DEBUG_Q921_DUMP) if (pri->debug & PRI_DEBUG_Q921_DUMP)
pri_message(pri, "-- Restarting T200 timer\n"); pri_message(pri, "-- Restarting T200 timer\n");
if (pri->t200_timer)
pri_schedule_del(pri, pri->t200_timer); pri_schedule_del(pri, pri->t200_timer);
pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri); pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
} }
@ -262,7 +260,6 @@ static void reschedule_t203(struct pri *pri)
{ {
if (pri->debug & PRI_DEBUG_Q921_DUMP) if (pri->debug & PRI_DEBUG_Q921_DUMP)
pri_message(pri, "-- Restarting T203 timer\n"); pri_message(pri, "-- Restarting T203 timer\n");
if (pri->t203_timer)
pri_schedule_del(pri, pri->t203_timer); pri_schedule_del(pri, pri->t203_timer);
pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri); pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
} }
@ -311,11 +308,9 @@ static pri_event *q921_ack_rx(struct pri *pri, int ack, int send_untransmitted_f
if (pri->debug & PRI_DEBUG_Q921_DUMP) if (pri->debug & PRI_DEBUG_Q921_DUMP)
pri_message(pri, "-- Since there was nothing left, stopping T200 counter\n"); pri_message(pri, "-- Since there was nothing left, stopping T200 counter\n");
/* Something was ACK'd. Stop T200 counter */ /* Something was ACK'd. Stop T200 counter */
if (pri->t200_timer) {
pri_schedule_del(pri, pri->t200_timer); pri_schedule_del(pri, pri->t200_timer);
pri->t200_timer = 0; pri->t200_timer = 0;
} }
}
if (pri->t203_timer) { if (pri->t203_timer) {
if (pri->debug & PRI_DEBUG_Q921_DUMP) if (pri->debug & PRI_DEBUG_Q921_DUMP)
pri_message(pri, "-- Stopping T203 counter since we got an ACK\n"); pri_message(pri, "-- Stopping T203 counter since we got an ACK\n");
@ -785,10 +780,8 @@ void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx)
pri_event *q921_dchannel_up(struct pri *pri) pri_event *q921_dchannel_up(struct pri *pri)
{ {
/* Stop any SABME retransmissions */ /* Stop any SABME retransmissions */
if (pri->sabme_timer) {
pri_schedule_del(pri, pri->sabme_timer); pri_schedule_del(pri, pri->sabme_timer);
pri->sabme_timer = 0; pri->sabme_timer = 0;
}
/* Reset any rejects */ /* Reset any rejects */
pri->sentrej = 0; pri->sentrej = 0;
@ -833,11 +826,8 @@ void q921_reset(struct pri *pri)
pri->v_na = 0; pri->v_na = 0;
pri->window = pri->timers[PRI_TIMER_K]; pri->window = pri->timers[PRI_TIMER_K];
pri->windowlen = 0; pri->windowlen = 0;
if (pri->sabme_timer)
pri_schedule_del(pri, pri->sabme_timer); pri_schedule_del(pri, pri->sabme_timer);
if (pri->t203_timer)
pri_schedule_del(pri, pri->t203_timer); pri_schedule_del(pri, pri->t203_timer);
if (pri->t200_timer)
pri_schedule_del(pri, pri->t200_timer); pri_schedule_del(pri, pri->t200_timer);
pri->sabme_timer = 0; pri->sabme_timer = 0;
pri->sabme_count = 0; pri->sabme_count = 0;
@ -909,10 +899,8 @@ static pri_event *q921_receive_MDL(struct pri *pri, q921_u *h, int len)
pri_message(pri, "TEI assignment received for invalid Ri %02x (our is %02x)\n", ri, pri->ri); pri_message(pri, "TEI assignment received for invalid Ri %02x (our is %02x)\n", ri, pri->ri);
return NULL; return NULL;
} }
if (pri->t202_timer) {
pri_schedule_del(pri, pri->t202_timer); pri_schedule_del(pri, pri->t202_timer);
pri->t202_timer = 0; pri->t202_timer = 0;
}
if (pri->subchannel && (pri->subchannel->tei == tei)) { if (pri->subchannel && (pri->subchannel->tei == tei)) {
pri_error(pri, "TEI already assigned (new is %d, current is %d)\n", tei, pri->subchannel->tei); pri_error(pri, "TEI already assigned (new is %d, current is %d)\n", tei, pri->subchannel->tei);
q921_tei_release_and_reacquire(pri); q921_tei_release_and_reacquire(pri);
@ -1082,10 +1070,8 @@ static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len)
} }
} }
/* Reset t200 timer if it was somehow going */ /* Reset t200 timer if it was somehow going */
if (pri->t200_timer) {
pri_schedule_del(pri, pri->t200_timer); pri_schedule_del(pri, pri->t200_timer);
pri->t200_timer = 0; pri->t200_timer = 0;
}
/* Reset and restart t203 timer */ /* Reset and restart t203 timer */
reschedule_t203(pri); reschedule_t203(pri);
} }

9
q931.c
View File

@ -3116,7 +3116,6 @@ static void q931_destroy(struct pri *ctrl, int cr, q931_call *c)
"NEW_HANGUP DEBUG: Destroying the call, ourstate %s, peerstate %s\n", "NEW_HANGUP DEBUG: Destroying the call, ourstate %s, peerstate %s\n",
q931_call_state_str(cur->ourcallstate), q931_call_state_str(cur->ourcallstate),
q931_call_state_str(cur->peercallstate)); q931_call_state_str(cur->peercallstate));
if (cur->retranstimer)
pri_schedule_del(ctrl, cur->retranstimer); pri_schedule_del(ctrl, cur->retranstimer);
pri_call_apdu_queue_cleanup(cur); pri_call_apdu_queue_cleanup(cur);
free(cur); free(cur);
@ -3754,7 +3753,6 @@ int q931_connect(struct pri *ctrl, q931_call *c, int channel, int nonisdn)
c->peercallstate = Q931_CALL_STATE_ACTIVE; c->peercallstate = Q931_CALL_STATE_ACTIVE;
c->alive = 1; c->alive = 1;
/* Connect request timer */ /* Connect request timer */
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
c->retranstimer = 0; c->retranstimer = 0;
if ((c->ourcallstate == Q931_CALL_STATE_CONNECT_REQUEST) && (ctrl->bri || (!ctrl->subchannel))) if ((c->ourcallstate == Q931_CALL_STATE_CONNECT_REQUEST) && (ctrl->bri || (!ctrl->subchannel)))
@ -3797,7 +3795,6 @@ int q931_release(struct pri *ctrl, q931_call *c, int cause)
c->causecode = CODE_CCITT; c->causecode = CODE_CCITT;
c->causeloc = LOC_PRIV_NET_LOCAL_USER; c->causeloc = LOC_PRIV_NET_LOCAL_USER;
if (c->acked) { if (c->acked) {
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
if (!c->t308_timedout) { if (!c->t308_timedout) {
c->retranstimer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T308], pri_release_timeout, c); c->retranstimer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T308], pri_release_timeout, c);
@ -3845,7 +3842,6 @@ int q931_disconnect(struct pri *ctrl, q931_call *c, int cause)
c->causecode = CODE_CCITT; c->causecode = CODE_CCITT;
c->causeloc = LOC_PRIV_NET_LOCAL_USER; c->causeloc = LOC_PRIV_NET_LOCAL_USER;
c->sendhangupack = 1; c->sendhangupack = 1;
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
c->retranstimer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T305], pri_disconnect_timeout, c); c->retranstimer = pri_schedule_event(ctrl, ctrl->timers[PRI_TIMER_T305], pri_disconnect_timeout, c);
return send_message(ctrl, c, Q931_DISCONNECT, disconnect_ies); return send_message(ctrl, c, Q931_DISCONNECT, disconnect_ies);
@ -4210,7 +4206,6 @@ static int prepare_to_handle_q931_message(struct pri *ctrl, q931_mh *mh, q931_ca
c->progressmask = 0; c->progressmask = 0;
break; break;
case Q931_CONNECT_ACKNOWLEDGE: case Q931_CONNECT_ACKNOWLEDGE:
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
c->retranstimer = 0; c->retranstimer = 0;
break; break;
@ -4220,13 +4215,11 @@ static int prepare_to_handle_q931_message(struct pri *ctrl, q931_mh *mh, q931_ca
c->causecode = -1; c->causecode = -1;
c->causeloc = -1; c->causeloc = -1;
c->aoc_units = -1; c->aoc_units = -1;
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
c->retranstimer = 0; c->retranstimer = 0;
c->useruserinfo[0] = '\0'; c->useruserinfo[0] = '\0';
break; break;
case Q931_RELEASE_COMPLETE: case Q931_RELEASE_COMPLETE:
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
c->retranstimer = 0; c->retranstimer = 0;
c->useruserinfo[0] = '\0'; c->useruserinfo[0] = '\0';
@ -5102,7 +5095,6 @@ static int pri_internal_clear(void *data)
struct pri *ctrl = c->pri; struct pri *ctrl = c->pri;
int res; int res;
if (c->retranstimer)
pri_schedule_del(ctrl, c->retranstimer); pri_schedule_del(ctrl, c->retranstimer);
c->retranstimer = 0; c->retranstimer = 0;
c->useruserinfo[0] = '\0'; c->useruserinfo[0] = '\0';
@ -5190,7 +5182,6 @@ void q931_dl_indication(struct pri *ctrl, int event)
pri_message(ctrl, DBGHEAD "cancel call %d on channel %d in state %d (%s)\n", DBGINFO, pri_message(ctrl, DBGHEAD "cancel call %d on channel %d in state %d (%s)\n", DBGINFO,
cur->cr, cur->channelno, cur->ourcallstate, cur->cr, cur->channelno, cur->ourcallstate,
q931_call_state_str(cur->ourcallstate)); q931_call_state_str(cur->ourcallstate));
if (cur->retranstimer)
pri_schedule_del(ctrl, cur->retranstimer); pri_schedule_del(ctrl, cur->retranstimer);
cur->retranstimer = pri_schedule_event(ctrl, 0, pri_dl_down_cancelcall, cur); cur->retranstimer = pri_schedule_event(ctrl, 0, pri_dl_down_cancelcall, cur);
} }