libFirm
Linked Lists

Doubly linked lists. More...

Macros

#define LIST_HEAD_INIT(name)   { &(name), &(name) }
 Static initializer for a list header.
#define LIST_HEAD(name)   struct list_head name = LIST_HEAD_INIT(name)
 Defines a (static) list reference.
#define INIT_LIST_HEAD(ptr)
 Initializes a list header.
#define list_entry(ptr, type, member)   _list_container_of(ptr, type, member)
 list_entry - get the struct for this entry
#define list_for_each(pos, head)   for (pos = (head)->next; pos != (head); pos = pos->next)
 list_for_each - iterate over a list
#define list_for_each_prev(pos, head)   for (pos = (head)->prev; pos != (head); pos = pos->prev)
 list_for_each_prev - iterate over a list backwards
#define list_for_each_safe(pos, n, head)
 list_for_each_safe - iterate over a list safe against removal of list entry
#define list_for_each_entry(type, pos, head, member)
 list_for_each_entry - iterate over list of given type
#define list_for_each_entry_reverse(type, pos, head, member)
 list_for_each_entry_reverse - iterate backwards over list of given type.
#define list_for_each_entry_safe(type, pos, n, head, member)
 list_for_each_entry_safe - iterate over list of given type safe against removal of list entry

Typedefs

typedef struct list_head list_head
 List Header.

Functions

static void __list_add (struct list_head *new_node, struct list_head *prev, struct list_head *next)
 Inserts a new entry between two known consecutive entries.
static void list_add (struct list_head *new_node, struct list_head *head)
 Adds a new entry.
static void list_add_tail (struct list_head *new_node, struct list_head *head)
 Adds a new entry.
static void __list_del (struct list_head *prev, struct list_head *next)
 Deletes a list entry by making the prev/next entries point to each other.
static void list_del (struct list_head *entry)
 Deletes entry from list.
static void list_del_init (struct list_head *entry)
 Deletes entry from list and reinitialize it.
static void list_move (struct list_head *list, struct list_head *head)
 Deletes from one list and add as another's head.
static void list_move_tail (struct list_head *list, struct list_head *head)
 Deletes from one list and add as another's tail.
static int list_empty (const struct list_head *head)
 Tests whether a list is empty.
static void __list_splice (struct list_head *list, struct list_head *head)
 Join two nonempty lists.
static void list_splice (struct list_head *list, struct list_head *head)
 list_splice - join two lists
static void list_splice_init (struct list_head *list, struct list_head *head)
 list_splice_init - join two lists and reinitialize the emptied list.

Detailed Description

Doubly linked lists.

Simple doubly linked list implementation.

Some of the internal functions ("__xxx") are useful when manipulating whole lists rather than single entries, as sometimes we already know the next/prev entries and we can generate better code by using them directly rather than using the generic single-entry routines.

Macro Definition Documentation

#define INIT_LIST_HEAD (   ptr)
Value:
do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

Initializes a list header.

Definition at line 37 of file list.h.

Referenced by list_del_init(), and list_splice_init().

#define list_entry (   ptr,
  type,
  member 
)    _list_container_of(ptr, type, member)

list_entry - get the struct for this entry

Parameters
ptrthe &struct list_head pointer.
typethe type of the struct this is embedded in.
memberthe name of the list_struct within the struct.

Definition at line 220 of file list.h.

#define list_for_each (   pos,
  head 
)    for (pos = (head)->next; pos != (head); pos = pos->next)

list_for_each - iterate over a list

Parameters
posthe &struct list_head to use as a loop counter.
headthe head for your list.

Definition at line 228 of file list.h.

#define list_for_each_entry (   type,
  pos,
  head,
  member 
)
Value:
for (type *pos = list_entry((head)->next, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, type, member))

list_for_each_entry - iterate over list of given type

Parameters
typethe type of the struct where the listhead is embedded in
posthe type * to use as a loop counter.
headthe head for your list.
memberthe name of the list_struct within the struct.

Definition at line 256 of file list.h.

#define list_for_each_entry_reverse (   type,
  pos,
  head,
  member 
)
Value:
for (type *pos = list_entry((head)->prev, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, type, member))

list_for_each_entry_reverse - iterate backwards over list of given type.

Parameters
typethe type of the struct where the listhead is embedded in
posthe type * to use as a loop counter.
headthe head for your list.
memberthe name of the list_struct within the struct.

Definition at line 268 of file list.h.

#define list_for_each_entry_safe (   type,
  pos,
  n,
  head,
  member 
)
Value:
for (type *pos = list_entry((head)->next, type, member), \
*n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))

list_for_each_entry_safe - iterate over list of given type safe against removal of list entry

Parameters
typethe type of the struct where the listhead is embedded in
posthe type * to use as a loop counter.
nanother type * to use as temporary storage
headthe head for your list.
memberthe name of the list_struct within the struct.

Definition at line 282 of file list.h.

#define list_for_each_prev (   pos,
  head 
)    for (pos = (head)->prev; pos != (head); pos = pos->prev)

list_for_each_prev - iterate over a list backwards

Parameters
posthe &struct list_head to use as a loop counter.
headthe head for your list.

Definition at line 236 of file list.h.

#define list_for_each_safe (   pos,
  n,
  head 
)
Value:
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)

list_for_each_safe - iterate over a list safe against removal of list entry

Parameters
posthe &struct list_head to use as a loop counter.
nanother &struct list_head to use as temporary storage
headthe head for your list.

Definition at line 245 of file list.h.

#define LIST_HEAD (   name)    struct list_head name = LIST_HEAD_INIT(name)

Defines a (static) list reference.

Definition at line 33 of file list.h.

#define LIST_HEAD_INIT (   name)    { &(name), &(name) }

Static initializer for a list header.

Definition at line 30 of file list.h.

Typedef Documentation

typedef struct list_head list_head

List Header.

Put this into all list elements and at the place where you want to keep references to the list.

Definition at line 27 of file list.h.

Function Documentation

static void __list_add ( struct list_head new_node,
struct list_head prev,
struct list_head next 
)
inlinestatic

Inserts a new entry between two known consecutive entries.

This is only for internal list manipulation where we know the prev/next entries already!

Definition at line 59 of file list.h.

Referenced by list_add(), and list_add_tail().

static void __list_del ( struct list_head prev,
struct list_head next 
)
inlinestatic

Deletes a list entry by making the prev/next entries point to each other.

This is only for internal list manipulation where we know the prev/next entries already!

Definition at line 102 of file list.h.

Referenced by list_del(), list_del_init(), list_move(), and list_move_tail().

static void __list_splice ( struct list_head list,
struct list_head head 
)
inlinestatic

Join two nonempty lists.

Note
Use list_splice() if list is possibly empty.
Parameters
listthe new list to add.
headthe place to add it in the first list.

Definition at line 173 of file list.h.

Referenced by list_splice(), and list_splice_init().

static void list_add ( struct list_head new_node,
struct list_head head 
)
inlinestatic

Adds a new entry.

Parameters
new_nodenew entry to be added
headlist head to add it after

Insert a new entry after the specified head. This is good for implementing stacks.

Definition at line 77 of file list.h.

References __list_add().

Referenced by list_move().

static void list_add_tail ( struct list_head new_node,
struct list_head head 
)
inlinestatic

Adds a new entry.

Parameters
new_nodenew entry to be added
headlist head to add it before

Insert a new entry before the specified head. This is useful for implementing queues.

Definition at line 90 of file list.h.

References __list_add().

Referenced by list_move_tail().

static void list_del ( struct list_head entry)
inlinestatic

Deletes entry from list.

Parameters
entrythe element to delete from the list.
Note
list_empty on entry does not return true after this, the entry is in an undefined state.

Definition at line 116 of file list.h.

References __list_del().

static void list_del_init ( struct list_head entry)
inlinestatic

Deletes entry from list and reinitialize it.

Parameters
entrythe element to delete from the list.

Definition at line 128 of file list.h.

References __list_del(), and INIT_LIST_HEAD.

static int list_empty ( const struct list_head head)
inlinestatic

Tests whether a list is empty.

Parameters
headthe list to test.

Definition at line 161 of file list.h.

Referenced by list_splice(), and list_splice_init().

static void list_move ( struct list_head list,
struct list_head head 
)
inlinestatic

Deletes from one list and add as another's head.

Parameters
listthe entry to move
headthe head that will precede our entry

Definition at line 139 of file list.h.

References __list_del(), and list_add().

static void list_move_tail ( struct list_head list,
struct list_head head 
)
inlinestatic

Deletes from one list and add as another's tail.

Parameters
listthe entry to move
headthe head that will follow our entry

Definition at line 150 of file list.h.

References __list_del(), and list_add_tail().

static void list_splice ( struct list_head list,
struct list_head head 
)
inlinestatic

list_splice - join two lists

Parameters
listthe new list to add.
headthe place to add it in the first list.

Definition at line 192 of file list.h.

References __list_splice(), and list_empty().

static void list_splice_init ( struct list_head list,
struct list_head head 
)
inlinestatic

list_splice_init - join two lists and reinitialize the emptied list.

Parameters
listthe new list to add.
headthe place to add it in the first list.

The list at list is reinitialized

Definition at line 205 of file list.h.

References __list_splice(), INIT_LIST_HEAD, and list_empty().