os_list Struct Reference
[Linked Lists]

#include <list.h>


Data Fields

struct os_list_node head


Detailed Description

A circular, doubly-linked list of nodes.

Structures to be stored in a list should contains a struct os_list_node as the first field.

   struct foo {
      struct os_list_node node;
      int bar;
      ...
   };
Going to/from a struct foo to a list node is then simple.
   struct os_list_node *node;
   struct foo *foo;
   [...]
   node = &foo->node;
   foo = (struct foo *)node
Lists must be initialized with os_list_init() before adding nodes with os_list_add_tail(). The node at the head of the list is obtained with os_list_head(). Nodes are removed from the list with os_list_del().

A list can be interated from the head to the tail using:

   struct os_list_node *node;
   for (node = os_list_head(list); node != os_list_end(list); node = node->next) {
      struct foo *foo = (struct foo *)node;
      ...
   }

In the above loop, the current list node cannot be removed (with os_list_del()). If this is required use this form of loop:

   struct os_list_node *node, *next;
   for (node = os_list_head(list), next = node->next;
        node != os_list_end(list);
        node = next, next = node->next) {
      struct foo *foo = (struct foo *)node;
      ...
      os_list_del(node);
      ...
   }

The documentation for this struct was generated from the following file:

Generated on Wed Oct 27 15:14:03 2010 for oska by  doxygen 1.5.5