GTGList.h
Go to the documentation of this file.
#ifndef GTG_LIST_H
#define GTG_LIST_H
struct gtg_list {
struct gtg_list *prev;
struct gtg_list *next;
};
typedef struct gtg_list* gtg_list_t;
#define GTG_LIST_INIT(ptr) \
do { \
(ptr)->prev = (ptr); \
(ptr)->next = (ptr); \
} while(0)
#define GTG_LIST(name) \
struct gtg_list name; \
GTG_LIST_INIT(&name)
#define gtg_list_entry(ptr, type, member) \
((type *)((char *)(ptr) - (char *)(&((type *)0)->member)))
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __gtg_list_add(gtg_list_t lnew,
gtg_list_t prev,
gtg_list_t next)
{
next->prev = lnew;
lnew->next = next;
lnew->prev = prev;
prev->next = lnew;
}
static inline void gtg_list_add(gtg_list_t lnew, gtg_list_t head)
{
__gtg_list_add(lnew, head, head->next);
}
static inline void gtg_list_add_tail(gtg_list_t lnew, gtg_list_t head)
{
__gtg_list_add(lnew, head->prev, head);
}
static inline void __gtg_list_del(gtg_list_t prev, gtg_list_t next)
{
next->prev = prev;
prev->next = next;
}
static inline void gtg_list_del(gtg_list_t entry)
{
__gtg_list_del(entry->prev, entry->next);
GTG_LIST_INIT(entry);
}
#define gtg_list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#define gtg_list_for_each_reverse(pos, head) \
for (pos = (head)->prev; pos != (head); pos = pos->prev)
#define gtg_list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define gtg_list_for_each_entry(pos, head, member) \
for (pos = gtg_list_entry((head)->next, typeof(*pos), member); \
&pos->member != (head); \
pos = gtg_list_entry(pos->member.next, typeof(*pos), member))
#define gtg_list_for_each_entry_safe(pos, n, head, member) \
for (pos = gtg_list_entry((head)->next, typeof(*pos), member), \
n = gtg_list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = gtg_list_entry(n->member.next, typeof(*n), member))
static inline int gtg_list_size(gtg_list_t l)
{
int res = 0;
gtg_list_t ptr = NULL;
gtg_list_for_each(ptr, l)
res++;
return res;
}
#endif /* GTG_LIST_H */
gtg_list
Definition: GTGList.h:4
GTG_LIST_INIT
#define GTG_LIST_INIT(ptr)
initialize a list.
Definition: GTGList.h:16
gtg_list_for_each
#define gtg_list_for_each(pos, head)
Definition: GTGList.h:112
__gtg_list_del
static void __gtg_list_del(gtg_list_t prev, gtg_list_t next)
Definition: GTGList.h:88
gtg_list::prev
struct gtg_list * prev
Definition: GTGList.h:5
__gtg_list_add
static void __gtg_list_add(gtg_list_t lnew, gtg_list_t prev, gtg_list_t next)
Definition: GTGList.h:49
gtg_list_del
static void gtg_list_del(gtg_list_t entry)
delete an entry from its list and reinitialize it.
Definition: GTGList.h:99
gtg_list_t
struct gtg_list * gtg_list_t
Definition: GTGList.h:9
gtg_list::next
struct gtg_list * next
Definition: GTGList.h:6
gtg_list_add
static void gtg_list_add(gtg_list_t lnew, gtg_list_t head)
Insert a new entry after the specified head.
Definition: GTGList.h:65
gtg_list_size
static int gtg_list_size(gtg_list_t l)
Definition: GTGList.h:164
gtg_list_add_tail
static void gtg_list_add_tail(gtg_list_t lnew, gtg_list_t head)
Insert a new entry before the specified head (ie. at the tail of the list).
Definition: GTGList.h:76