SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
dlist.h
Go to the documentation of this file.
1 
54 #ifndef __SOLAR_CAPTURE_DLIST_H__
55 #define __SOLAR_CAPTURE_DLIST_H__
56 
60 struct sc_dlist {
61  struct sc_dlist* prev;
62  struct sc_dlist* next;
63 };
64 
71 #define SC_CONTAINER(c_type, mbr_name, p_mbr) \
72  ( (c_type*) ((char*)(p_mbr) - SC_MEMBER_OFFSET(c_type, mbr_name)) )
73 
83 #define SC_DLIST_FOR_EACH_OBJ(list, iter, mbr) \
84  for( (iter) = SC_CONTAINER(typeof(*(iter)), mbr, (list)->next); \
85  &(iter)->mbr != (list); \
86  (iter) = SC_CONTAINER(typeof(*(iter)), mbr, (iter)->mbr.next) )
87 
96 #define SC_DLIST_FOR_EACH_OBJ_SAFE(list, iter, next_entry, mbr) \
97  for( (iter) = SC_CONTAINER(typeof(*(iter)), mbr, (list)->next), \
98  (next_entry) = SC_CONTAINER(typeof(*(iter)), mbr, (iter)->mbr.next); \
99  &(iter)->mbr != (list); \
100  (iter) = (next_entry), \
101  (next_entry) = SC_CONTAINER(typeof(*(iter)), mbr, (iter)->mbr.next) )
102 
107 static inline void sc_dlist_init(struct sc_dlist* list)
108 {
109  list->next = list->prev = list;
110 }
111 
115 static inline int sc_dlist_is_empty(const struct sc_dlist* list)
116 {
117  return list->next == list;
118 }
119 
124 static inline void sc_dlist_push_head(struct sc_dlist* list, struct sc_dlist* l)
125 {
126  l->next = list->next;
127  l->prev = list;
128  list->next = l->next->prev = l;
129 }
130 
135 static inline void sc_dlist_push_tail(struct sc_dlist* list, struct sc_dlist* l)
136 {
137  l->next = list;
138  l->prev = list->prev;
139  list->prev = l->prev->next = l;
140 }
141 
145 static inline void sc_dlist_remove(struct sc_dlist* l)
146 {
147  l->prev->next = l->next;
148  l->next->prev = l->prev;
149 }
150 
154 static inline struct sc_dlist* sc_dlist_pop_head(struct sc_dlist* list)
155 {
156  struct sc_dlist* l;
157  l = list->next;
158  sc_dlist_remove(l);
159  return l;
160 }
161 
165 static inline struct sc_dlist* sc_dlist_pop_tail(struct sc_dlist* list)
166 {
167  struct sc_dlist* l;
168  l = list->prev;
169  sc_dlist_remove(l);
170  return l;
171 }
172 
173 
174 #endif /* __SOLAR_CAPTURE_DLIST_H__ */
175 
static void sc_dlist_init(struct sc_dlist *list)
Initialise a pre-allocated sc_dlist to be an empty doubly linked list.
Definition: dlist.h:107
static void sc_dlist_remove(struct sc_dlist *l)
Remove an item from the list.
Definition: dlist.h:145
Doubly linked list pointers.
Definition: dlist.h:60
static struct sc_dlist * sc_dlist_pop_tail(struct sc_dlist *list)
Pop the tail of a list.
Definition: dlist.h:165
struct sc_dlist * next
Definition: dlist.h:62
static int sc_dlist_is_empty(const struct sc_dlist *list)
Check if a doubly linked list is empty, returns 1 if true 0 otherwise.
Definition: dlist.h:115
struct sc_dlist * prev
Definition: dlist.h:61
static struct sc_dlist * sc_dlist_pop_head(struct sc_dlist *list)
Pop off the head of a list.
Definition: dlist.h:154
static void sc_dlist_push_head(struct sc_dlist *list, struct sc_dlist *l)
Prepend an item to the head of a doubly-linked list.
Definition: dlist.h:124
static void sc_dlist_push_tail(struct sc_dlist *list, struct sc_dlist *l)
Append an item to the tail of a doubly-linked list.
Definition: dlist.h:135