RTEMS Logo

RTEMS 4.9.4 On-Line Library


Chains Creating a Chain

PREV UP NEXT Bookshelf RTEMS Ada User's Guide

28.3.2: Creating a Chain

To create a chain you need to declare a chain control then add nodes to the control. Consider a user structure and chain control:

typedef struct foo
{
  rtems.chain_node node;
  uint8_t char*    data;
} foo;

rtems.chain_control chain;

Add nodes with the following code:

rtems.chain_initialize_empty (&chain);

for (i = 0; i < count; i++)
{
  foo* bar = malloc (sizeof (foo));
  if (!foo)
    return -1;
  bar->data = malloc (size);
  rtems.chain_append (&chain, &bar->node);
}

The chain is initialized and the nodes allocated and appended to the chain. This is an example of a pool of buffers.


PREV UP NEXT Bookshelf RTEMS Ada User's Guide

Copyright © 1988-2008 OAR Corporation