// Process all the chunks up to the last one while (cptr != self->last_chunk)
{
(*self->item_destructor)(cptr->items[i++], closure); if (i == ITEMS_PER_CHUNK)
{
cptr = cptr->next;
i = 0;
}
}
// Process all the items in the last chunk while (i < self->writer)
{
(*self->item_destructor)(cptr->items[i++], closure);
}
}
}
// Now free all the chunks except the last one struct chunk *cptr = self->first_chunk; while (cptr->next != NULL)
{ struct chunk *next = cptr->next;
free(cptr);
cptr = next;
}
/*****************************************************************************/ void *
fifo_remove_item(struct fifo *self)
{ void *item = NULL; if (self != NULL)
{ // More than one chunk in the fifo? if (self->first_chunk != self->last_chunk)
{ /* We're not reading the last chunk. There
* must be something in the fifo */
item = self->first_chunk->items[self->reader++];
/* At the end of this chunk? */ if (self->reader == ITEMS_PER_CHUNK)
{ struct chunk *old_chunk = self->first_chunk;
self->first_chunk = old_chunk->next;
free(old_chunk);
self->reader = 0;
}
} elseif (self->reader < self->writer)
{ /* We're reading the last chunk */
item = self->first_chunk->items[self->reader++]; if (self->reader == self->writer)
{ // fifo is now empty. We can reset the pointers // to prevent unnecessary allocations in the future.
self->reader = 0;
self->writer = 0;
}
}
} return item;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.