mirror of
https://git.proxmox.com/git/mirror_corosync-qdevice
synced 2025-08-12 22:47:13 +00:00
timer-list: Add functions for get and set interval
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
This commit is contained in:
parent
af4f8826dc
commit
0360d14b49
@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user