From 01c5a3ea27dc37d11ee6b9583d40c176031f1ff5 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 22 Mar 2013 03:16:35 +0000 Subject: Fixed #1648: Timer heap new API cancel_if_active() should not assert if given bad entry git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4449 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/timer.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'pjlib') diff --git a/pjlib/src/pj/timer.c b/pjlib/src/pj/timer.c index 47209fbe..07752f82 100644 --- a/pjlib/src/pj/timer.c +++ b/pjlib/src/pj/timer.c @@ -45,6 +45,13 @@ #define DEFAULT_MAX_TIMED_OUT_PER_POLL (64) +enum +{ + F_DONT_CALL = 1, + F_DONT_ASSERT = 2, + F_SET_ID = 4 +}; + /** * The implementation of timer heap. @@ -313,7 +320,7 @@ static pj_status_t schedule_entry( pj_timer_heap_t *ht, static int cancel( pj_timer_heap_t *ht, pj_timer_entry *entry, - int dont_call) + unsigned flags) { long timer_node_slot; @@ -330,14 +337,15 @@ static int cancel( pj_timer_heap_t *ht, if (entry != ht->heap[timer_node_slot]) { - pj_assert(entry == ht->heap[timer_node_slot]); + if ((flags & F_DONT_ASSERT) == 0) + pj_assert(entry == ht->heap[timer_node_slot]); return 0; } else { remove_node( ht, timer_node_slot); - if (dont_call == 0) + if ((flags & F_DONT_CALL) == 0) // Call the close hook. (*ht->callback)(ht, entry); return 1; @@ -551,7 +559,7 @@ PJ_DEF(pj_status_t) pj_timer_heap_schedule_w_grp_lock(pj_timer_heap_t *ht, static int cancel_timer(pj_timer_heap_t *ht, pj_timer_entry *entry, - pj_bool_t set_id, + unsigned flags, int id_val) { int count; @@ -559,8 +567,8 @@ static int cancel_timer(pj_timer_heap_t *ht, PJ_ASSERT_RETURN(ht && entry, PJ_EINVAL); lock_timer_heap(ht); - count = cancel(ht, entry, 1); - if (set_id) { + count = cancel(ht, entry, flags | F_DONT_CALL); + if (flags & F_SET_ID) { entry->id = id_val; } if (entry->_grp_lock) { @@ -576,14 +584,14 @@ static int cancel_timer(pj_timer_heap_t *ht, PJ_DEF(int) pj_timer_heap_cancel( pj_timer_heap_t *ht, pj_timer_entry *entry) { - return cancel_timer(ht, entry, PJ_FALSE, 0); + return cancel_timer(ht, entry, 0, 0); } PJ_DEF(int) pj_timer_heap_cancel_if_active(pj_timer_heap_t *ht, pj_timer_entry *entry, int id_val) { - return cancel_timer(ht, entry, PJ_TRUE, id_val); + return cancel_timer(ht, entry, F_SET_ID | F_DONT_ASSERT, id_val); } PJ_DEF(unsigned) pj_timer_heap_poll( pj_timer_heap_t *ht, -- cgit v1.2.3