btstack_run_loop_base: assert timer to add is not already in list

This commit is contained in:
Matthias Ringwald 2021-03-04 11:42:11 +01:00
parent 31bea0195b
commit 9111a8ae53

View File

@ -81,14 +81,9 @@ bool btstack_run_loop_base_remove_timer(btstack_timer_source_t *ts){
void btstack_run_loop_base_add_timer(btstack_timer_source_t *ts){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) &btstack_run_loop_base_timers; it->next ; it = it->next){
// don't add timer that's already in there
if ((btstack_timer_source_t *) it->next == ts){
log_error( "btstack_run_loop_timer_add error: timer to add already in list!");
return;
}
// exit if list timeout is after new timeout
uint32_t list_timeout = ((btstack_timer_source_t *) it->next)->timeout;
int32_t delta = btstack_time_delta(ts->timeout, list_timeout);
btstack_timer_source_t * next = (btstack_timer_source_t *) it->next;
btstack_assert(next != ts);
int32_t delta = btstack_time_delta(ts->timeout, next->timeout);
if (delta < 0) break;
}
ts->item.next = it->next;