RTEMS Logo

RTEMS 4.9.6 On-Line Library


Chains Iterating a Chain

PREV UP NEXT Bookshelf RTEMS C User's Guide

28.3.3: Iterating a Chain

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;
    }
  }
}


PREV UP NEXT Bookshelf RTEMS C User's Guide

Copyright © 1988-2008 OAR Corporation