Iterating a chain is a common function. The example shows how to iterate the buffer pool chain created in the last section to find buffers starting with a specific string. If the buffer is located it is extracted from the chain and placed on another chain:
void foobar (const char* match, rtems.chain_control* chain, rtems.chain_control* out) { rtems.chain_node* node; foo* bar; rtems.chain_initialize_empty (out); node = chain->first; while (!rtems.chain_is_tail (chain, node)) { bar = (foo*) node; if (strcmp (match, bar->data) == 0) { rtems.chain_node* next_node = node->next; rtems.chain_extract (node); rtems.chain_append (out, node); node = next_node; } } }
Copyright © 1988-2008 OAR Corporation