libubox
C utility functions for OpenWrt.
list.h File Reference
#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  list_head
 

Macros

#define prefetch(x)
 
#define container_of(ptr, type, member)
 
#define container_of_safe(ptr, type, member)
 
#define LIST_HEAD_INIT(name)   { &(name), &(name) }
 
#define LIST_HEAD(name)   struct list_head name = LIST_HEAD_INIT(name)
 
#define list_entry(ptr, type, field)   container_of(ptr, type, field)
 
#define list_first_entry(ptr, type, field)   list_entry((ptr)->next, type, field)
 
#define list_last_entry(ptr, type, field)   list_entry((ptr)->prev, type, field)
 
#define list_next_entry(pos, member)   list_entry((pos)->member.next, typeof(*(pos)), member)
 
#define list_entry_is_h(p, h, field)   (&p->field == (h))
 
#define list_for_each(p, head)    for (p = (head)->next; p != (head); p = p->next)
 
#define list_for_each_safe(p, n, head)    for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
 
#define list_for_each_entry(p, h, field)
 
#define list_for_each_entry_continue(p, h, field)
 
#define list_for_each_entry_continue_reverse(p, h, field)
 
#define list_for_each_entry_safe(p, n, h, field)
 
#define list_for_each_entry_reverse(p, h, field)
 
#define list_for_each_prev(p, h)   for (p = (h)->prev; p != (h); p = p->prev)
 
#define list_for_each_prev_safe(p, n, h)   for (p = (h)->prev, n = p->prev; p != (h); p = n, n = p->prev)
 

Functions

static void INIT_LIST_HEAD (struct list_head *list)
 
static bool list_empty (const struct list_head *head)
 
static bool list_is_first (const struct list_head *list, const struct list_head *head)
 
static bool list_is_last (const struct list_head *list, const struct list_head *head)
 
static void _list_del (struct list_head *entry)
 
static void list_del (struct list_head *entry)
 
static void _list_add (struct list_head *_new, struct list_head *prev, struct list_head *next)
 
static void list_del_init (struct list_head *entry)
 
static void list_add (struct list_head *_new, struct list_head *head)
 
static void list_add_tail (struct list_head *_new, struct list_head *head)
 
static void list_move (struct list_head *list, struct list_head *head)
 
static void list_move_tail (struct list_head *entry, struct list_head *head)
 
static void _list_splice (const struct list_head *list, struct list_head *prev, struct list_head *next)
 
static void list_splice (const struct list_head *list, struct list_head *head)
 
static void list_splice_tail (struct list_head *list, struct list_head *head)
 
static void list_splice_init (struct list_head *list, struct list_head *head)
 
static void list_splice_tail_init (struct list_head *list, struct list_head *head)
 

Macro Definition Documentation

◆ container_of

#define container_of (   ptr,
  type,
  member 
)
Value:
({ \
const __typeof__(((type *) NULL)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member)); \
})
uint8_t type
Definition: udebug-proto.h:0

Definition at line 38 of file list.h.

◆ container_of_safe

#define container_of_safe (   ptr,
  type,
  member 
)
Value:
({ \
const __typeof__(((type *) NULL)->member) *__mptr = (ptr); \
__mptr ? (type *)((char *) __mptr - offsetof(type, member)) : NULL; \
})

Definition at line 46 of file list.h.

◆ list_entry

#define list_entry (   ptr,
  type,
  field 
)    container_of(ptr, type, field)

Definition at line 120 of file list.h.

◆ list_entry_is_h

#define list_entry_is_h (   p,
  h,
  field 
)    (&p->field == (h))

Definition at line 124 of file list.h.

◆ list_first_entry

#define list_first_entry (   ptr,
  type,
  field 
)    list_entry((ptr)->next, type, field)

Definition at line 121 of file list.h.

◆ list_for_each

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

Definition at line 126 of file list.h.

◆ list_for_each_entry

#define list_for_each_entry (   p,
  h,
  field 
)
Value:
for (p = list_first_entry(h, __typeof__(*p), field); &p->field != (h); \
p = list_entry(p->field.next, __typeof__(*p), field))
#define list_entry(ptr, type, field)
Definition: list.h:120
#define list_first_entry(ptr, type, field)
Definition: list.h:121

Definition at line 132 of file list.h.

◆ list_for_each_entry_continue

#define list_for_each_entry_continue (   p,
  h,
  field 
)
Value:
for (p = list_next_entry(p, field); \
!list_entry_is_h(p, h, field); \
p = list_next_entry(p, field))
#define list_next_entry(pos, member)
Definition: list.h:123
#define list_entry_is_h(p, h, field)
Definition: list.h:124

Definition at line 136 of file list.h.

◆ list_for_each_entry_continue_reverse

#define list_for_each_entry_continue_reverse (   p,
  h,
  field 
)
Value:
for (p = list_prev_entry(p, field); \
!list_entry_is_h(p, h, field); \
p = list_prev_entry(p, field))

Definition at line 141 of file list.h.

◆ list_for_each_entry_reverse

#define list_for_each_entry_reverse (   p,
  h,
  field 
)
Value:
for (p = list_last_entry(h, __typeof__(*p), field); &p->field != (h); \
p = list_entry(p->field.prev, __typeof__(*p), field))
#define list_last_entry(ptr, type, field)
Definition: list.h:122

Definition at line 151 of file list.h.

◆ list_for_each_entry_safe

#define list_for_each_entry_safe (   p,
  n,
  h,
  field 
)
Value:
for (p = list_first_entry(h, __typeof__(*p), field), \
n = list_entry(p->field.next, __typeof__(*p), field); &p->field != (h);\
p = n, n = list_entry(n->field.next, __typeof__(*n), field))

Definition at line 146 of file list.h.

◆ list_for_each_prev

#define list_for_each_prev (   p,
 
)    for (p = (h)->prev; p != (h); p = p->prev)

Definition at line 155 of file list.h.

◆ list_for_each_prev_safe

#define list_for_each_prev_safe (   p,
  n,
 
)    for (p = (h)->prev, n = p->prev; p != (h); p = n, n = p->prev)

Definition at line 156 of file list.h.

◆ list_for_each_safe

#define list_for_each_safe (   p,
  n,
  head 
)     for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)

Definition at line 129 of file list.h.

◆ LIST_HEAD

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

Definition at line 60 of file list.h.

◆ LIST_HEAD_INIT

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

Definition at line 58 of file list.h.

◆ list_last_entry

#define list_last_entry (   ptr,
  type,
  field 
)    list_entry((ptr)->prev, type, field)

Definition at line 122 of file list.h.

◆ list_next_entry

#define list_next_entry (   pos,
  member 
)    list_entry((pos)->member.next, typeof(*(pos)), member)

Definition at line 123 of file list.h.

◆ prefetch

#define prefetch (   x)

Definition at line 35 of file list.h.

Function Documentation

◆ _list_add()

static void _list_add ( struct list_head _new,
struct list_head prev,
struct list_head next 
)
inlinestatic

Definition at line 103 of file list.h.

105 {
106 
107  next->prev = _new;
108  _new->next = next;
109  _new->prev = prev;
110  prev->next = _new;
111 }
struct list_head * next
Definition: list.h:54
struct list_head * prev
Definition: list.h:55
Here is the caller graph for this function:

◆ _list_del()

static void _list_del ( struct list_head entry)
inlinestatic

Definition at line 89 of file list.h.

90 {
91  entry->next->prev = entry->prev;
92  entry->prev->next = entry->next;
93 }
Here is the caller graph for this function:

◆ _list_splice()

static void _list_splice ( const struct list_head list,
struct list_head prev,
struct list_head next 
)
inlinestatic

Definition at line 185 of file list.h.

187 {
188  struct list_head *first;
189  struct list_head *last;
190 
191  if (list_empty(list))
192  return;
193 
194  first = list->next;
195  last = list->prev;
196  first->prev = prev;
197  prev->next = first;
198  last->next = next;
199  next->prev = last;
200 }
static bool list_empty(const struct list_head *head)
Definition: list.h:69
Definition: list.h:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ INIT_LIST_HEAD()

static void INIT_LIST_HEAD ( struct list_head list)
inlinestatic

Definition at line 63 of file list.h.

64 {
65  list->next = list->prev = list;
66 }
Here is the caller graph for this function:

◆ list_add()

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

Definition at line 159 of file list.h.

160 {
161  _list_add(_new, head, head->next);
162 }
static void _list_add(struct list_head *_new, struct list_head *prev, struct list_head *next)
Definition: list.h:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_add_tail()

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

Definition at line 165 of file list.h.

166 {
167  _list_add(_new, head->prev, head);
168 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_del()

static void list_del ( struct list_head entry)
inlinestatic

Definition at line 96 of file list.h.

97 {
98  _list_del(entry);
99  entry->next = entry->prev = NULL;
100 }
static void _list_del(struct list_head *entry)
Definition: list.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_del_init()

static void list_del_init ( struct list_head entry)
inlinestatic

Definition at line 114 of file list.h.

115 {
116  _list_del(entry);
117  INIT_LIST_HEAD(entry);
118 }
static void INIT_LIST_HEAD(struct list_head *list)
Definition: list.h:63
Here is the call graph for this function:

◆ list_empty()

static bool list_empty ( const struct list_head head)
inlinestatic

Definition at line 69 of file list.h.

70 {
71  return (head->next == head);
72 }
Here is the caller graph for this function:

◆ list_is_first()

static bool list_is_first ( const struct list_head list,
const struct list_head head 
)
inlinestatic

Definition at line 75 of file list.h.

77 {
78  return list->prev == head;
79 }
Here is the caller graph for this function:

◆ list_is_last()

static bool list_is_last ( const struct list_head list,
const struct list_head head 
)
inlinestatic

Definition at line 82 of file list.h.

84 {
85  return list->next == head;
86 }
Here is the caller graph for this function:

◆ list_move()

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

Definition at line 171 of file list.h.

172 {
173  _list_del(list);
174  list_add(list, head);
175 }
static void list_add(struct list_head *_new, struct list_head *head)
Definition: list.h:159
Here is the call graph for this function:

◆ list_move_tail()

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

Definition at line 178 of file list.h.

179 {
180  _list_del(entry);
181  list_add_tail(entry, head);
182 }
static void list_add_tail(struct list_head *_new, struct list_head *head)
Definition: list.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_splice()

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

Definition at line 203 of file list.h.

204 {
205  _list_splice(list, head, head->next);
206 }
static void _list_splice(const struct list_head *list, struct list_head *prev, struct list_head *next)
Definition: list.h:185
Here is the call graph for this function:

◆ list_splice_init()

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

Definition at line 215 of file list.h.

216 {
217  _list_splice(list, head, head->next);
218  INIT_LIST_HEAD(list);
219 }
Here is the call graph for this function:

◆ list_splice_tail()

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

Definition at line 209 of file list.h.

210 {
211  _list_splice(list, head->prev, head);
212 }
Here is the call graph for this function:

◆ list_splice_tail_init()

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

Definition at line 222 of file list.h.

223 {
224  _list_splice(list, head->prev, head);
225  INIT_LIST_HEAD(list);
226 }
Here is the call graph for this function: