diff --git a/qdevices/test-timer-list.c b/qdevices/test-timer-list.c index 82d5899..9705896 100644 --- a/qdevices/test-timer-list.c +++ b/qdevices/test-timer-list.c @@ -154,6 +154,19 @@ check_timer_list_basics(void) assert(timer_list_time_to_expire(&tlist) == PR_INTERVAL_NO_TIMEOUT); assert(timer_list_time_to_expire_ms(&tlist) == ~((uint32_t)0)); + /* + * Check changing of interval + */ + timer_list_fn1_called = 0; + tlist_entry = timer_list_add(&tlist, LONG_TIMEOUT, timer_list_fn1, &timer_list_fn1_called, timer_list_fn1); + assert(tlist_entry != NULL); + assert(timer_list_entry_set_interval(&tlist, tlist_entry, SHORT_TIMEOUT) == 0); + (void)poll(NULL, 0, SHORT_TIMEOUT); + assert(timer_list_time_to_expire(&tlist) == 0); + assert(timer_list_time_to_expire_ms(&tlist) == 0); + timer_list_expire(&tlist); + assert(timer_list_fn1_called == 1); + /* * Test speed and more entries */ @@ -224,6 +237,7 @@ check_timer_heap(void) assert(timer_list_debug_is_valid_heap(&tlist)); assert(tlist.size == i + 1); assert(tlist.entries[0] == tlist_entry_small); + assert(timer_list_entry_get_interval(tlist_entry_small) == SHORT_TIMEOUT); /* * Remove all items @@ -233,6 +247,7 @@ check_timer_heap(void) assert(timer_list_debug_is_valid_heap(&tlist)); assert(tlist.entries[0] == tlist_entry_small); + assert(timer_list_entry_get_interval(tlist_entry[i]) == LONG_TIMEOUT * (i + 1)); } /* diff --git a/qdevices/timer-list.c b/qdevices/timer-list.c index dde10eb..2168b77 100644 --- a/qdevices/timer-list.c +++ b/qdevices/timer-list.c @@ -461,3 +461,33 @@ timer_list_free(struct timer_list *tlist) timer_list_init(tlist); } + +PRUint32 +timer_list_entry_get_interval(const struct timer_list_entry *entry) +{ + + return (entry->interval); +} + +int +timer_list_entry_set_interval(struct timer_list *tlist, struct timer_list_entry *entry, + PRUint32 interval) +{ + + if (interval < 1 || interval > TIMER_LIST_MAX_INTERVAL) { + return (-1); + } + + if (!entry->is_active) { + return (-1); + } + + timer_list_heap_delete(tlist, entry); + + entry->interval = interval; + entry->epoch = PR_IntervalNow(); + + timer_list_insert_into_list(tlist, entry); + + return (0); +} diff --git a/qdevices/timer-list.h b/qdevices/timer-list.h index b620c7b..6bfc4bd 100644 --- a/qdevices/timer-list.h +++ b/qdevices/timer-list.h @@ -94,6 +94,12 @@ extern void timer_list_free(struct timer_list *tlist); extern int timer_list_debug_is_valid_heap(struct timer_list *tlist); +extern PRUint32 timer_list_entry_get_interval( + const struct timer_list_entry *entry); + +extern int timer_list_entry_set_interval( + struct timer_list *tlist, struct timer_list_entry *entry, PRUint32 interval); + #ifdef __cplusplus } #endif