libubox
C utility functions for OpenWrt.
safe_list.c File Reference
#include "safe_list.h"

Go to the source code of this file.

Data Structures

struct  safe_list_iterator
 

Functions

static void __safe_list_set_iterator (struct safe_list *list, struct safe_list_iterator *i)
 
static void __safe_list_del_iterator (struct safe_list_iterator *i)
 
static void __safe_list_move_iterator (struct safe_list *list, struct safe_list_iterator *i)
 
int safe_list_for_each (struct safe_list *head, int(*cb)(void *ctx, struct safe_list *list), void *ctx)
 
void safe_list_add (struct safe_list *list, struct safe_list *head)
 
void safe_list_add_first (struct safe_list *list, struct safe_list *head)
 
void safe_list_del (struct safe_list *list)
 

Function Documentation

◆ __safe_list_del_iterator()

static void __safe_list_del_iterator ( struct safe_list_iterator i)
static

Definition at line 47 of file safe_list.c.

48 {
49  *i->head = i->next_i;
50  if (i->next_i)
51  i->next_i->head = i->head;
52 }
struct safe_list_iterator ** head
Definition: safe_list.c:22
struct safe_list_iterator * next_i
Definition: safe_list.c:23
Here is the caller graph for this function:

◆ __safe_list_move_iterator()

static void __safe_list_move_iterator ( struct safe_list list,
struct safe_list_iterator i 
)
static

Definition at line 55 of file safe_list.c.

57 {
59  __safe_list_set_iterator(list, i);
60 }
static void __safe_list_del_iterator(struct safe_list_iterator *i)
Definition: safe_list.c:47
static void __safe_list_set_iterator(struct safe_list *list, struct safe_list_iterator *i)
Definition: safe_list.c:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __safe_list_set_iterator()

static void __safe_list_set_iterator ( struct safe_list list,
struct safe_list_iterator i 
)
static

Definition at line 28 of file safe_list.c.

30 {
31  struct safe_list_iterator *next_i;
32  struct safe_list *next;
33 
34  next = list_entry(list->list.next, struct safe_list, list);
35  next_i = next->i;
36 
37  next->i = i;
38  i->next = next;
39  i->head = &next->i;
40 
41  i->next_i = next_i;
42  if (next_i)
43  next_i->head = &i->next_i;
44 }
#define list_entry(ptr, type, field)
Definition: list.h:120
struct list_head * next
Definition: list.h:54
struct safe_list * next
Definition: safe_list.c:24
struct list_head list
Definition: safe_list.h:36
struct safe_list_iterator * i
Definition: safe_list.h:37
Here is the caller graph for this function:

◆ safe_list_add()

void safe_list_add ( struct safe_list list,
struct safe_list head 
)

Definition at line 83 of file safe_list.c.

84 {
85  list->i = NULL;
86  list_add_tail(&list->list, &head->list);
87 }
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:

◆ safe_list_add_first()

void safe_list_add_first ( struct safe_list list,
struct safe_list head 
)

Definition at line 89 of file safe_list.c.

90 {
91  list->i = NULL;
92  list_add(&list->list, &head->list);
93 }
static void list_add(struct list_head *_new, struct list_head *head)
Definition: list.h:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ safe_list_del()

void safe_list_del ( struct safe_list list)

Definition at line 95 of file safe_list.c.

96 {
97  struct safe_list_iterator *i, *next_i, **tail;
98  struct safe_list *next;
99 
100  next = list_entry(list->list.next, struct safe_list, list);
101  list_del(&list->list);
102 
103  if (!list->i)
104  return;
105 
106  next_i = next->i;
107  tail = &next->i;
108 
109  for (i = list->i; i; i = i->next_i) {
110  tail = &i->next_i;
111  i->next = next;
112  }
113 
114  next->i = list->i;
115  list->i->head = &next->i;
116  *tail = next_i;
117  if (next_i)
118  next_i->head = tail;
119 
120  list->i = NULL;
121 }
static void list_del(struct list_head *entry)
Definition: list.h:96
Here is the call graph for this function:
Here is the caller graph for this function:

◆ safe_list_for_each()

int safe_list_for_each ( struct safe_list head,
int(*)(void *ctx, struct safe_list *list)  cb,
void *  ctx 
)

Definition at line 62 of file safe_list.c.

65 {
66  struct safe_list_iterator i;
67  struct safe_list *cur;
68  int ret = 0;
69 
70  for (cur = list_entry(head->list.next, struct safe_list, list),
72  cur != head;
73  cur = i.next, __safe_list_move_iterator(cur, &i)) {
74  ret = cb(ctx, cur);
75  if (ret)
76  break;
77  }
78 
80  return ret;
81 }
static void __safe_list_move_iterator(struct safe_list *list, struct safe_list_iterator *i)
Definition: safe_list.c:55
Here is the call graph for this function:
Here is the caller graph for this function: