1
0
mirror of https://github.com/DigitalDevices/octonet.git synced 2023-10-10 13:36:52 +02:00
octonet/octoscan/list.h

54 lines
1.4 KiB
C
Raw Normal View History

2015-12-21 13:49:44 +01:00
struct list_head {
2016-06-08 21:00:49 +02:00
struct list_head *prev;
struct list_head *next;
2015-12-21 13:49:44 +01:00
};
2016-06-08 21:00:49 +02:00
#define list_entry(lh, st, field) container_of(lh, st, field)
#define list_first_entry(lh, st, field) list_entry((lh)->next, st, field)
#define list_next_entry(lh, field) list_entry((lh)->field.next, typeof(*(lh)), field)
2015-12-21 13:49:44 +01:00
2016-06-08 21:00:49 +02:00
static inline void list_head_init(struct list_head *lh)
2015-12-21 13:49:44 +01:00
{
2016-06-08 21:00:49 +02:00
lh->prev = lh->next = lh;
2015-12-21 13:49:44 +01:00
}
2016-06-08 21:00:49 +02:00
static inline int list_empty(const struct list_head *lh)
2015-12-21 13:49:44 +01:00
{
2016-06-08 21:00:49 +02:00
return (lh == lh->next);
2015-12-21 13:49:44 +01:00
}
2016-06-08 21:00:49 +02:00
static inline void list_add(struct list_head *add, struct list_head *lh)
2015-12-21 13:49:44 +01:00
{
2016-06-08 21:00:49 +02:00
add->prev = lh;
add->next = lh->next;
lh->next->prev = add;
lh->next = add;
2015-12-21 13:49:44 +01:00
}
2016-06-08 21:00:49 +02:00
static inline void list_add_tail(struct list_head *add, struct list_head *lh)
2015-12-21 13:49:44 +01:00
{
2016-06-08 21:00:49 +02:00
add->prev = lh->prev;
add->next = lh;
lh->prev->next = add;
lh->prev = add;
2015-12-21 13:49:44 +01:00
}
2016-06-08 21:00:49 +02:00
static inline void list_del(struct list_head *del)
2015-12-21 13:49:44 +01:00
{
2016-06-08 21:00:49 +02:00
del->prev->next = del->next;
del->next->prev = del->prev;
del->prev = del->next = NULL;
2015-12-21 13:49:44 +01:00
}
2016-06-08 21:00:49 +02:00
#define list_for_each_entry(cur, lh, field) \
for ((cur) = list_entry((lh)->next, typeof(*(cur)), field); \
&(cur)->field != (lh); \
(cur) = list_entry((cur)->field.next, typeof(*(cur)), field))
2015-12-21 13:49:44 +01:00
2016-06-08 21:00:49 +02:00
#define list_for_each_entry_safe(cur, nxt, lh, field) \
for ((cur) = list_entry((lh)->next, typeof(*(cur)), field), \
(nxt) = list_next_entry((cur), field); \
&(cur)->field != (lh); \
(cur) = (nxt), (nxt) = list_next_entry((nxt), field))
2015-12-21 13:49:44 +01:00