mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
evtimer: optimized adding
This commit is contained in:
parent
ded2a44c77
commit
111f021eb3
@ -35,8 +35,7 @@
|
|||||||
* handle the pointer hack in this function */
|
* handle the pointer hack in this function */
|
||||||
void evtimer_add_event_to_list(evtimer_t *evtimer, evtimer_event_t *event)
|
void evtimer_add_event_to_list(evtimer_t *evtimer, evtimer_event_t *event)
|
||||||
{
|
{
|
||||||
uint32_t delta_sum = 0;
|
DEBUG("evtimer: new event offset %" PRIu32 " ms\n", event->offset);
|
||||||
|
|
||||||
/* we want list->next to point to the first list element. thus we take the
|
/* we want list->next to point to the first list element. thus we take the
|
||||||
* *address* of evtimer->events, then cast it from (evtimer_event_t **) to
|
* *address* of evtimer->events, then cast it from (evtimer_event_t **) to
|
||||||
* (evtimer_event_t*). After that, list->next actually equals
|
* (evtimer_event_t*). After that, list->next actually equals
|
||||||
@ -45,20 +44,32 @@ void evtimer_add_event_to_list(evtimer_t *evtimer, evtimer_event_t *event)
|
|||||||
|
|
||||||
while (list->next) {
|
while (list->next) {
|
||||||
evtimer_event_t *list_entry = list->next;
|
evtimer_event_t *list_entry = list->next;
|
||||||
if ((list_entry->offset + delta_sum) > event->offset) {
|
/* Stop when new event time is nearer then next */
|
||||||
|
if (event->offset < list_entry->offset) {
|
||||||
|
DEBUG("evtimer: next %" PRIu32 " < %" PRIu32 " ms\n",
|
||||||
|
event->offset, list_entry->offset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delta_sum += list_entry->offset;
|
/* Set event offset relative to previous event */
|
||||||
|
event->offset -= list_entry->offset;
|
||||||
list = list->next;
|
list = list->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEBUG("evtimer: new event relativ offset %" PRIu32 " ms\n", event->offset);
|
||||||
|
|
||||||
|
/* Set found next bigger event after new event */
|
||||||
event->next = list->next;
|
event->next = list->next;
|
||||||
if (list->next) {
|
if (list->next) {
|
||||||
|
/* Set offset following event relative to new event */
|
||||||
evtimer_event_t *next_entry = list->next;
|
evtimer_event_t *next_entry = list->next;
|
||||||
next_entry->offset += delta_sum;
|
DEBUG("evtimer: recalculate offset for %" PRIu32 " ms\n",
|
||||||
|
next_entry->offset);
|
||||||
|
|
||||||
next_entry->offset -= event->offset;
|
next_entry->offset -= event->offset;
|
||||||
|
|
||||||
|
DEBUG("evtimer: resulting new event offset %" PRIu32 " ms\n",
|
||||||
|
next_entry->offset);
|
||||||
}
|
}
|
||||||
event->offset -= delta_sum;
|
|
||||||
|
|
||||||
list->next = event;
|
list->next = event;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user