libqb  1.9.0
Data Structures | Macros | Functions
qblist.h File Reference

This is a kernel style list implementation. More...

#include <stdint.h>
#include <qb/qbdefs.h>
Include dependency graph for qblist.h:

Data Structures

struct  qb_list_head
 

Macros

#define QB_LIST_DECLARE(name)   struct qb_list_head name = { &(name), &(name) }
 Declare and initialize a list head. More...
 
#define QB_INIT_LIST_HEAD(ptr)
 
#define qb_list_entry(ptr, type, member)   ((type *)((char *)(ptr)-(char*)(&((type *)0)->member)))
 Get the struct for this entry. More...
 
#define qb_list_first_entry(ptr, type, member)   qb_list_entry((ptr)->next, type, member)
 Get the first element from a list. More...
 
#define qb_list_for_each(pos, head)   for (pos = (head)->next; pos != (head); pos = pos->next)
 Iterate over a list. More...
 
#define qb_list_for_each_reverse(pos, head)   for (pos = (head)->prev; pos != (head); pos = pos->prev)
 Iterate over a list backwards. More...
 
#define qb_list_for_each_safe(pos, n, head)
 Iterate over a list safe against removal of list entry. More...
 
#define qb_list_for_each_entry(pos, head, member)
 Iterate over list of given type. More...
 
#define qb_list_for_each_entry_reverse(pos, head, member)
 Iterate backwards over list of given type. More...
 
#define qb_list_for_each_entry_safe(pos, n, head, member)
 Iterate over list of given type safe against removal of list entry. More...
 
#define qb_list_for_each_entry_safe_reverse(pos, n, head, member)
 Iterate backwards over list safe against removal. More...
 
#define qb_list_for_each_entry_from(pos, head, member)
 Iterate over list of given type from the current point. More...
 

Functions

static void qb_list_init (struct qb_list_head *head)
 Initialize the list entry. More...
 
static void qb_list_add (struct qb_list_head *element, struct qb_list_head *head)
 Add this element to the list. More...
 
static void qb_list_add_tail (struct qb_list_head *element, struct qb_list_head *head)
 Add to the list (but at the end of the list). More...
 
static void qb_list_del (struct qb_list_head *_remove)
 Delete an entry from the list. More...
 
static void qb_list_replace (struct qb_list_head *old_one, struct qb_list_head *new_one)
 Replace old entry by new one. More...
 
static int qb_list_is_last (const struct qb_list_head *list, const struct qb_list_head *head)
 Tests whether list is the last entry in list head. More...
 
static int32_t qb_list_empty (const struct qb_list_head *head)
 A quick test to see if the list is empty (pointing to it's self). More...
 
static void qb_list_splice (struct qb_list_head *list, struct qb_list_head *head)
 Join two lists. More...
 
static void qb_list_splice_tail (struct qb_list_head *list, struct qb_list_head *head)
 Join two lists, each list being a queue. More...
 
static int32_t qb_list_length (struct qb_list_head *head)
 Count the number of items in the list. More...
 

Detailed Description

This is a kernel style list implementation.

Author
Steven Dake sdake.nosp@m.@red.nosp@m.hat.c.nosp@m.om

Macro Definition Documentation

◆ QB_INIT_LIST_HEAD

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

◆ QB_LIST_DECLARE

#define QB_LIST_DECLARE (   name)    struct qb_list_head name = { &(name), &(name) }

Declare and initialize a list head.

◆ qb_list_entry

#define qb_list_entry (   ptr,
  type,
  member 
)    ((type *)((char *)(ptr)-(char*)(&((type *)0)->member)))

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.

◆ qb_list_first_entry

#define qb_list_first_entry (   ptr,
  type,
  member 
)    qb_list_entry((ptr)->next, type, member)

Get the first element from a list.

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

◆ qb_list_for_each

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

Iterate over a list.

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

◆ qb_list_for_each_entry

#define qb_list_for_each_entry (   pos,
  head,
  member 
)
Value:
for (pos = qb_list_entry((head)->next, typeof(*pos), member); \
&pos->member != (head); \
pos = qb_list_entry(pos->member.next, typeof(*pos), member))
#define qb_list_entry(ptr, type, member)
Get the struct for this entry.
Definition: qblist.h:196

Iterate over list of given type.

Parameters
posthe type * to use as a loop counter.
headthe head for your list.
memberthe name of the list_struct within the struct.

◆ qb_list_for_each_entry_from

#define qb_list_for_each_entry_from (   pos,
  head,
  member 
)
Value:
for (; &pos->member != (head); \
pos = qb_list_entry(pos->member.next, typeof(*pos), member))
#define qb_list_entry(ptr, type, member)
Get the struct for this entry.
Definition: qblist.h:196

Iterate over list of given type from the current point.

Parameters
posthe type * to use as a loop cursor.
headthe head for your list.
memberthe name of the list_struct within the struct.

◆ qb_list_for_each_entry_reverse

#define qb_list_for_each_entry_reverse (   pos,
  head,
  member 
)
Value:
for (pos = qb_list_entry((head)->prev, typeof(*pos), member); \
&pos->member != (head); \
pos = qb_list_entry(pos->member.prev, typeof(*pos), member))
#define qb_list_entry(ptr, type, member)
Get the struct for this entry.
Definition: qblist.h:196

Iterate backwards over list of given type.

Parameters
posthe type to use as a loop counter.
headthe head for your list.
memberthe name of the list_struct within the struct.

◆ qb_list_for_each_entry_safe

#define qb_list_for_each_entry_safe (   pos,
  n,
  head,
  member 
)
Value:
for (pos = qb_list_entry((head)->next, typeof(*pos), member), \
n = qb_list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = qb_list_entry(n->member.next, typeof(*n), member))
#define qb_list_entry(ptr, type, member)
Get the struct for this entry.
Definition: qblist.h:196

Iterate over list of given type safe against removal of list entry.

Parameters
posthe type * to use as a loop cursor.
nanother type * to use as temporary storage
headthe head for your list.
memberthe name of the list_struct within the struct.

◆ qb_list_for_each_entry_safe_reverse

#define qb_list_for_each_entry_safe_reverse (   pos,
  n,
  head,
  member 
)
Value:
for (pos = qb_list_entry((head)->prev, typeof(*pos), member), \
n = qb_list_entry(pos->member.prev, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = qb_list_entry(n->member.prev, typeof(*n), member))
#define qb_list_entry(ptr, type, member)
Get the struct for this entry.
Definition: qblist.h:196

Iterate backwards over list safe against removal.

Parameters
posthe type * to use as a loop cursor.
nanother type * to use as temporary storage
headthe head for your list.
memberthe name of the list_struct within the struct.

◆ qb_list_for_each_reverse

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

Iterate over a list backwards.

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

◆ qb_list_for_each_safe

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

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.

Function Documentation

◆ qb_list_add()

static void qb_list_add ( struct qb_list_head element,
struct qb_list_head head 
)
inlinestatic

Add this element to the list.

Parameters
elementthe new element to insert.
headpointer to the list head

References qb_list_head::next, and qb_list_head::prev.

◆ qb_list_add_tail()

static void qb_list_add_tail ( struct qb_list_head element,
struct qb_list_head head 
)
inlinestatic

Add to the list (but at the end of the list).

Parameters
elementpointer to the element to add
headpointer to the list head
See also
qb_list_add()

References qb_list_head::next, and qb_list_head::prev.

◆ qb_list_del()

static void qb_list_del ( struct qb_list_head _remove)
inlinestatic

Delete an entry from the list.

Parameters
_removethe list item to remove

References qb_list_head::next, and qb_list_head::prev.

◆ qb_list_empty()

static int32_t qb_list_empty ( const struct qb_list_head head)
inlinestatic

A quick test to see if the list is empty (pointing to it's self).

Parameters
headpointer to the list head
Returns
boolean true/false

References qb_list_head::next.

Referenced by qb_list_splice(), and qb_list_splice_tail().

◆ qb_list_init()

static void qb_list_init ( struct qb_list_head head)
inlinestatic

Initialize the list entry.

Points next and prev pointers to head.

Parameters
headpointer to the list head

References qb_list_head::next, and qb_list_head::prev.

◆ qb_list_is_last()

static int qb_list_is_last ( const struct qb_list_head list,
const struct qb_list_head head 
)
inlinestatic

Tests whether list is the last entry in list head.

Parameters
listthe entry to test
headthe head of the list
Returns
boolean true/false

References qb_list_head::next.

◆ qb_list_length()

static int32_t qb_list_length ( struct qb_list_head head)
inlinestatic

Count the number of items in the list.

Parameters
headthe head for your list.
Returns
length of the list.

References qb_list_for_each.

◆ qb_list_replace()

static void qb_list_replace ( struct qb_list_head old_one,
struct qb_list_head new_one 
)
inlinestatic

Replace old entry by new one.

Parameters
old_onethe element to be replaced
new_onethe new element to insert

References qb_list_head::next, and qb_list_head::prev.

◆ qb_list_splice()

static void qb_list_splice ( struct qb_list_head list,
struct qb_list_head head 
)
inlinestatic

Join two lists.

Parameters
listthe new list to add.
headthe place to add it in the first list.
Note
The "list" is reinitialised

References qb_list_head::next, qb_list_head::prev, and qb_list_empty().

◆ qb_list_splice_tail()

static void qb_list_splice_tail ( struct qb_list_head list,
struct qb_list_head head 
)
inlinestatic

Join two lists, each list being a queue.

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

References qb_list_head::next, qb_list_head::prev, and qb_list_empty().