Grouped list code in local functions, to be moved in the lists module.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14343 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
59723bfb2e
commit
312b29e5b8
|
@ -100,6 +100,59 @@ static inline bool is_timer(delta_list_t *dlhp, delta_list_t *dlp) {
|
||||||
return (bool)(dlp != dlhp);
|
return (bool)(dlp != dlhp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dequeues an element from the delta list.
|
||||||
|
*
|
||||||
|
* @param[in] dlp pointer to the delta list element
|
||||||
|
*
|
||||||
|
* @notapi
|
||||||
|
*/
|
||||||
|
static delta_list_t *dlist_dequeue(delta_list_t *dlp) {
|
||||||
|
|
||||||
|
dlp->prev->next = dlp->next;
|
||||||
|
dlp->next->prev = dlp->prev;
|
||||||
|
|
||||||
|
return dlp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dequeues an element from the delta list.
|
||||||
|
*
|
||||||
|
* @param[in] dlhp pointer to the delta list header
|
||||||
|
*
|
||||||
|
* @notapi
|
||||||
|
*/
|
||||||
|
static delta_list_t *dlist_remove_first(delta_list_t *dlhp) {
|
||||||
|
delta_list_t *dlp = dlhp->next;
|
||||||
|
|
||||||
|
dlhp->next = dlp->next;
|
||||||
|
dlhp->next->prev = dlhp;
|
||||||
|
|
||||||
|
return dlp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dlist_insert_after(delta_list_t *dlhp,
|
||||||
|
delta_list_t *dlp,
|
||||||
|
sysinterval_t delta) {
|
||||||
|
|
||||||
|
dlp->delta = delta;
|
||||||
|
dlp->prev = dlhp;
|
||||||
|
dlp->next = dlp->prev->next;
|
||||||
|
dlp->next->prev = dlp;
|
||||||
|
dlhp->next = dlp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dlist_insert_before(delta_list_t *dlhp,
|
||||||
|
delta_list_t *dlp,
|
||||||
|
sysinterval_t delta) {
|
||||||
|
|
||||||
|
dlp->delta = delta;
|
||||||
|
dlp->next = dlhp;
|
||||||
|
dlp->prev = dlp->next->prev;
|
||||||
|
dlp->prev->next = dlp;
|
||||||
|
dlhp->prev = dlp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delta list compression.
|
* @brief Delta list compression.
|
||||||
*
|
*
|
||||||
|
@ -158,11 +211,7 @@ static void vt_enqueue(virtual_timers_list_t *vtlp,
|
||||||
/* The delta list is empty, the current time becomes the new
|
/* The delta list is empty, the current time becomes the new
|
||||||
delta list base time, the timer is inserted.*/
|
delta list base time, the timer is inserted.*/
|
||||||
vtlp->lasttime = now;
|
vtlp->lasttime = now;
|
||||||
vtlp->dlist.next = &vtp->dlist;
|
dlist_insert_after(&vtlp->dlist, &vtp->dlist, delay);
|
||||||
vtlp->dlist.prev = &vtp->dlist;
|
|
||||||
vtp->dlist.next = &vtlp->dlist;
|
|
||||||
vtp->dlist.prev = &vtlp->dlist;
|
|
||||||
vtp->dlist.delta = delay;
|
|
||||||
|
|
||||||
#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION
|
#if CH_CFG_INTERVALS_SIZE > CH_CFG_ST_RESOLUTION
|
||||||
/* The delta could be too large for the physical timer to handle.*/
|
/* The delta could be too large for the physical timer to handle.*/
|
||||||
|
@ -222,11 +271,7 @@ static void vt_enqueue(virtual_timers_list_t *vtlp,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The timer is inserted in the delta list.*/
|
/* The timer is inserted in the delta list.*/
|
||||||
vtp->dlist.next = dlp;
|
dlist_insert_before(dlp, &vtp->dlist, delta);
|
||||||
vtp->dlist.prev = vtp->dlist.next->prev;
|
|
||||||
vtp->dlist.prev->next = &vtp->dlist;
|
|
||||||
dlp->prev = &vtp->dlist;
|
|
||||||
vtp->dlist.delta = delta;
|
|
||||||
|
|
||||||
/* Calculate new delta for the following entry.*/
|
/* Calculate new delta for the following entry.*/
|
||||||
dlp->delta -= delta;
|
dlp->delta -= delta;
|
||||||
|
@ -345,8 +390,7 @@ void chVTDoResetI(virtual_timer_t *vtp) {
|
||||||
vtp->dlist.next->delta += vtp->dlist.delta;
|
vtp->dlist.next->delta += vtp->dlist.delta;
|
||||||
|
|
||||||
/* Removing the element from the delta list, marking it as not armed.*/
|
/* Removing the element from the delta list, marking it as not armed.*/
|
||||||
vtp->dlist.prev->next = vtp->dlist.next;
|
dlist_dequeue(&vtp->dlist);
|
||||||
vtp->dlist.next->prev = vtp->dlist.prev;
|
|
||||||
vtp->dlist.next = NULL;
|
vtp->dlist.next = NULL;
|
||||||
|
|
||||||
/* The above code changes the value in the header when the removed element
|
/* The above code changes the value in the header when the removed element
|
||||||
|
@ -358,13 +402,14 @@ void chVTDoResetI(virtual_timer_t *vtp) {
|
||||||
/* If the timer is not the first of the list then it is simply unlinked
|
/* If the timer is not the first of the list then it is simply unlinked
|
||||||
else the operation is more complex.*/
|
else the operation is more complex.*/
|
||||||
if (!is_first_timer(&vtlp->dlist, &vtp->dlist)) {
|
if (!is_first_timer(&vtlp->dlist, &vtp->dlist)) {
|
||||||
|
|
||||||
/* Removing the element from the delta list.*/
|
/* Removing the element from the delta list.*/
|
||||||
vtp->dlist.prev->next = vtp->dlist.next;
|
dlist_dequeue(&vtp->dlist);
|
||||||
vtp->dlist.next->prev = vtp->dlist.prev;
|
|
||||||
|
|
||||||
/* Adding delta to the next element, if it is not the last one.*/
|
/* Adding delta to the next element, if it is not the last one.*/
|
||||||
if (is_timer(&vtlp->dlist, vtp->dlist.next))
|
if (is_timer(&vtlp->dlist, vtp->dlist.next)) {
|
||||||
vtp->dlist.next->delta += vtp->dlist.delta;
|
vtp->dlist.next->delta += vtp->dlist.delta;
|
||||||
|
}
|
||||||
|
|
||||||
/* Marking timer as not armed.*/
|
/* Marking timer as not armed.*/
|
||||||
vtp->dlist.next = NULL;
|
vtp->dlist.next = NULL;
|
||||||
|
@ -373,8 +418,7 @@ void chVTDoResetI(virtual_timer_t *vtp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Removing the first timer from the list, marking it as not armed.*/
|
/* Removing the first timer from the list, marking it as not armed.*/
|
||||||
vtlp->dlist.next = vtp->dlist.next;
|
dlist_remove_first(&vtlp->dlist);
|
||||||
vtlp->dlist.next->prev = &vtlp->dlist;
|
|
||||||
vtp->dlist.next = NULL;
|
vtp->dlist.next = NULL;
|
||||||
|
|
||||||
/* If the list become empty then the alarm timer is stopped and done.*/
|
/* If the list become empty then the alarm timer is stopped and done.*/
|
||||||
|
@ -387,12 +431,6 @@ void chVTDoResetI(virtual_timer_t *vtp) {
|
||||||
/* The delta of the removed timer is added to the new first timer.*/
|
/* The delta of the removed timer is added to the new first timer.*/
|
||||||
vtlp->dlist.next->delta += vtp->dlist.delta;
|
vtlp->dlist.next->delta += vtp->dlist.delta;
|
||||||
|
|
||||||
/* If the new first timer has a delta of zero then the alarm is not
|
|
||||||
modified, the already programmed alarm will serve it.*/
|
|
||||||
/* if (vtlp->dlist.next->delta == 0) {
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* Distance in ticks between the last alarm event and current time.*/
|
/* Distance in ticks between the last alarm event and current time.*/
|
||||||
nowdelta = chTimeDiffX(vtlp->lasttime, chVTGetSystemTimeX());
|
nowdelta = chTimeDiffX(vtlp->lasttime, chVTGetSystemTimeX());
|
||||||
|
|
||||||
|
@ -524,9 +562,8 @@ void chVTDoTickI(void) {
|
||||||
|
|
||||||
chDbgAssert((int)chTimeDiffX(vtlp->lasttime, now) >= 0, "back in time");
|
chDbgAssert((int)chTimeDiffX(vtlp->lasttime, now) >= 0, "back in time");
|
||||||
|
|
||||||
/* Removing the next timer from the list, marking it as not armed.*/
|
/* Removing the timer from the list, marking it as not armed.*/
|
||||||
dlp->next->prev = &vtlp->dlist;
|
dlist_dequeue(dlp);
|
||||||
vtlp->dlist.next = dlp->next;
|
|
||||||
dlp->next = NULL;
|
dlp->next = NULL;
|
||||||
|
|
||||||
/* If the list becomes empty then the timer is stopped.*/
|
/* If the list becomes empty then the timer is stopped.*/
|
||||||
|
|
Loading…
Reference in New Issue