Reuse memory for queued events.
Patch #109 - 2 provided by Giles Atkinson
This commit is contained in:
parent
0c59a77fc4
commit
9308c6b077
|
|
@ -93,12 +93,29 @@ void EVTaccept(
|
|||
num_modified = inst_queue->num_modified;
|
||||
/* Loop through list of items modified since last time */
|
||||
for(i = 0; i < num_modified; i++) {
|
||||
Evt_Inst_Event_t *stale, *next;
|
||||
|
||||
/* Get the index of the inst modified */
|
||||
index = inst_queue->modified_index[i];
|
||||
/* Update last_step for this index */
|
||||
inst_queue->last_step[index] = inst_queue->current[index];
|
||||
/* Reset the modified flag */
|
||||
inst_queue->modified[index] = MIF_FALSE;
|
||||
/* Move stale entries to the free list. */
|
||||
next = inst_queue->head[index];
|
||||
while (next) {
|
||||
if (next->event_time >= time ||
|
||||
&next->next == inst_queue->current[index]) {
|
||||
break;
|
||||
}
|
||||
stale = next;
|
||||
next = next->next;
|
||||
stale->next = inst_queue->free[index];
|
||||
inst_queue->free[index] = stale;
|
||||
}
|
||||
inst_queue->head[index] = next;
|
||||
if (!next)
|
||||
inst_queue->current[index] = &inst_queue->head[index];
|
||||
/* Update last_step for this index */
|
||||
inst_queue->last_step[index] = inst_queue->current[index];
|
||||
}
|
||||
/* Record the new last_time and reset number modified to zero */
|
||||
inst_queue->last_time = time;
|
||||
|
|
@ -109,12 +126,29 @@ void EVTaccept(
|
|||
num_modified = output_queue->num_modified;
|
||||
/* Loop through list of items modified since last time */
|
||||
for(i = 0; i < num_modified; i++) {
|
||||
Evt_Output_Event_t *stale, *next;
|
||||
|
||||
/* Get the index of the output modified */
|
||||
index = output_queue->modified_index[i];
|
||||
/* Update last_step for this index */
|
||||
output_queue->last_step[index] = output_queue->current[index];
|
||||
/* Reset the modified flag */
|
||||
output_queue->modified[index] = MIF_FALSE;
|
||||
/* Move stale entries to the free list. */
|
||||
next = output_queue->head[index];
|
||||
while (next) {
|
||||
if (next->event_time >= time ||
|
||||
&next->next == output_queue->current[index]) {
|
||||
break;
|
||||
}
|
||||
stale = next;
|
||||
next = next->next;
|
||||
stale->next = output_queue->free[index];
|
||||
output_queue->free[index] = stale;
|
||||
}
|
||||
output_queue->head[index] = next;
|
||||
if (!next)
|
||||
output_queue->current[index] = &output_queue->head[index];
|
||||
/* Update last_step for this index */
|
||||
output_queue->last_step[index] = output_queue->current[index];
|
||||
}
|
||||
/* Record the new last_time and reset number modified to zero */
|
||||
output_queue->last_time = time;
|
||||
|
|
|
|||
|
|
@ -132,8 +132,8 @@ static void EVTdequeue_output(
|
|||
/* Get pointer to next event in queue at this index */
|
||||
output = *(output_queue->current[index]);
|
||||
|
||||
/* If event time does not match current time, skip */
|
||||
if(output->event_time != time)
|
||||
/* If cleaned or event time does not match current time, skip */
|
||||
if(!output || output->event_time != time)
|
||||
continue;
|
||||
|
||||
/* It must match, so pull the event from the queue and process it */
|
||||
|
|
@ -232,8 +232,8 @@ void EVTdequeue_inst(
|
|||
/* Get pointer to next event in queue at this index */
|
||||
inst = *(inst_queue->current[index]);
|
||||
|
||||
/* If event time does not match current time, skip */
|
||||
if(inst->event_time != time)
|
||||
/* If cleaned or event time does not match current time, skip */
|
||||
if(!inst || inst->event_time != time)
|
||||
continue;
|
||||
|
||||
/* It must match, so pull the event from the queue and process it */
|
||||
|
|
|
|||
Loading…
Reference in New Issue