summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2013-03-22 03:16:35 +0000
committerBenny Prijono <bennylp@teluu.com>2013-03-22 03:16:35 +0000
commit01c5a3ea27dc37d11ee6b9583d40c176031f1ff5 (patch)
treeb435d971044d53de90101370fb3fe5046ba17bb5 /pjlib
parente815e81926d7319d412210764ac8e74c1c71b676 (diff)
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
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/src/pj/timer.c24
1 files changed, 16 insertions, 8 deletions
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,