Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
include/uk/list.h | 82 ++++++++++++++++++++---------------------------
1 file changed, 34 insertions(+), 48 deletions(-)
diff --git a/include/uk/list.h b/include/uk/list.h
index 265c371..80746f6 100644
--- a/include/uk/list.h
+++ b/include/uk/list.h
@@ -48,14 +48,12 @@ struct uk_list_head {
static inline void
UK_INIT_LIST_HEAD(struct uk_list_head *list)
{
-
list->next = list->prev = list;
}
static inline int
uk_list_empty(const struct uk_list_head *head)
{
-
return (head->next == head);
}
@@ -77,14 +75,12 @@ __uk_list_del(struct uk_list_head *prev, struct uk_list_head *next)
static inline void
__uk_list_del_entry(struct uk_list_head *entry)
{
-
__uk_list_del(entry->prev, entry->next);
}
static inline void
uk_list_del(struct uk_list_head *entry)
{
-
__uk_list_del(entry->prev, entry->next);
}
@@ -106,9 +102,8 @@ uk_list_replace_init(struct uk_list_head *old, struct uk_list_head *new)
static inline void
__uk_list_add(struct uk_list_head *new, struct uk_list_head *prev,
- struct uk_list_head *next)
+ struct uk_list_head *next)
{
-
next->prev = new;
new->next = next;
new->prev = prev;
@@ -118,7 +113,6 @@ __uk_list_add(struct uk_list_head *new, struct uk_list_head
*prev,
static inline void
uk_list_del_init(struct uk_list_head *entry)
{
-
uk_list_del(entry);
UK_INIT_LIST_HEAD(entry);
}
@@ -143,20 +137,22 @@ uk_list_del_init(struct uk_list_head *entry)
#define uk_list_prev_entry(ptr, member)
\
uk_list_entry(((ptr)->member.prev), typeof(*(ptr)), member)
-#define uk_list_for_each(p, head) \
+#define uk_list_for_each(p, head) \
for (p = (head)->next; p != (head); p = (p)->next)
-#define uk_list_for_each_safe(p, n, head) \
+#define uk_list_for_each_safe(p, n, head)
\
for (p = (head)->next, n = (p)->next; p != (head); p = n, n = (p)->next)
#define uk_list_for_each_entry(p, h, field) \
- for (p = uk_list_entry((h)->next, typeof(*p), field); &(p)->field !=
(h); \
- p = uk_list_entry((p)->field.next, typeof(*p), field))
+ for (p = uk_list_entry((h)->next, typeof(*p), field); \
+ &(p)->field != (h); \
+ p = uk_list_entry((p)->field.next, typeof(*p), field))
#define uk_list_for_each_entry_safe(p, n, h, field) \
for (p = uk_list_entry((h)->next, typeof(*p), field), \
- n = uk_list_entry((p)->field.next, typeof(*p), field); &(p)->field
!= (h);\
- p = n, n = uk_list_entry(n->field.next, typeof(*n), field))
+ n = uk_list_entry((p)->field.next, typeof(*p), field); \
+ &(p)->field != (h); \
+ p = n, n = uk_list_entry(n->field.next, typeof(*n), field))
#define uk_list_for_each_entry_from(p, h, field) \
for ( ; &(p)->field != (h); \
@@ -166,44 +162,44 @@ uk_list_del_init(struct uk_list_head *entry)
for (p = uk_list_next_entry((p), field); &(p)->field != (h); \
p = uk_list_next_entry((p), field))
-#define uk_list_for_each_entry_safe_from(pos, n, head, member) \
- for (n = uk_list_entry((pos)->member.next, typeof(*pos), member);
\
- &(pos)->member != (head);
\
+#define uk_list_for_each_entry_safe_from(pos, n, head, member)
\
+ for (n = uk_list_entry((pos)->member.next, typeof(*pos), member); \
+ &(pos)->member != (head); \
pos = n, n = uk_list_entry(n->member.next, typeof(*n), member))
#define uk_list_for_each_entry_reverse(p, h, field) \
- for (p = uk_list_entry((h)->prev, typeof(*p), field); &(p)->field !=
(h); \
- p = uk_list_entry((p)->field.prev, typeof(*p), field))
+ for (p = uk_list_entry((h)->prev, typeof(*p), field); \
+ &(p)->field != (h); \
+ p = uk_list_entry((p)->field.prev, typeof(*p), field))
#define uk_list_for_each_entry_safe_reverse(p, n, h, field) \
for (p = uk_list_entry((h)->prev, typeof(*p), field), \
- n = uk_list_entry((p)->field.prev, typeof(*p), field); &(p)->field
!= (h); \
- p = n, n = uk_list_entry(n->field.prev, typeof(*n), field))
+ n = uk_list_entry((p)->field.prev, typeof(*p), field); \
+ &(p)->field != (h); \
+ p = n, n = uk_list_entry(n->field.prev, typeof(*n), field))
-#define uk_list_for_each_entry_continue_reverse(p, h, field) \
- for (p = uk_list_entry((p)->field.prev, typeof(*p), field); &(p)->field
!= (h); \
- p = uk_list_entry((p)->field.prev, typeof(*p), field))
+#define uk_list_for_each_entry_continue_reverse(p, h, field)
\
+ for (p = uk_list_entry((p)->field.prev, typeof(*p), field); \
+ &(p)->field != (h); \
+ p = uk_list_entry((p)->field.prev, typeof(*p), field))
#define uk_list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = (p)->prev)
static inline void
uk_list_add(struct uk_list_head *new, struct uk_list_head *head)
{
-
__uk_list_add(new, head, head->next);
}
static inline void
uk_list_add_tail(struct uk_list_head *new, struct uk_list_head *head)
{
-
__uk_list_add(new, head->prev, head);
}
static inline void
uk_list_move(struct uk_list_head *list, struct uk_list_head *head)
{
-
uk_list_del(list);
uk_list_add(list, head);
}
@@ -211,14 +207,13 @@ uk_list_move(struct uk_list_head *list, struct
uk_list_head *head)
static inline void
uk_list_move_tail(struct uk_list_head *entry, struct uk_list_head *head)
{
-
uk_list_del(entry);
uk_list_add_tail(entry, head);
}
static inline void
__uk_list_splice(const struct uk_list_head *list, struct uk_list_head *prev,
- struct uk_list_head *next)
+ struct uk_list_head *next)
{
struct uk_list_head *first;
struct uk_list_head *last;
@@ -236,21 +231,18 @@ __uk_list_splice(const struct uk_list_head *list, struct
uk_list_head *prev,
static inline void
uk_list_splice(const struct uk_list_head *list, struct uk_list_head *head)
{
-
__uk_list_splice(list, head, head->next);
}
static inline void
uk_list_splice_tail(struct uk_list_head *list, struct uk_list_head *head)
{
-
__uk_list_splice(list, head->prev, head);
}
static inline void
uk_list_splice_init(struct uk_list_head *list, struct uk_list_head *head)
{
-
__uk_list_splice(list, head, head->next);
UK_INIT_LIST_HEAD(list);
}
@@ -258,7 +250,6 @@ uk_list_splice_init(struct uk_list_head *list, struct
uk_list_head *head)
static inline void
uk_list_splice_tail_init(struct uk_list_head *list, struct uk_list_head *head)
{
-
__uk_list_splice(list, head->prev, head);
UK_INIT_LIST_HEAD(list);
}
@@ -284,21 +275,18 @@ do {
\
static inline int
uk_hlist_unhashed(const struct uk_hlist_node *h)
{
-
return !h->pprev;
}
static inline int
uk_hlist_empty(const struct uk_hlist_head *h)
{
-
return !UK_READ_ONCE(h->first);
}
static inline void
uk_hlist_del(struct uk_hlist_node *n)
{
-
UK_WRITE_ONCE(*(n->pprev), n->next);
if (n->next != NULL)
n->next->pprev = n->pprev;
@@ -307,7 +295,6 @@ uk_hlist_del(struct uk_hlist_node *n)
static inline void
uk_hlist_del_init(struct uk_hlist_node *n)
{
-
if (uk_hlist_unhashed(n))
return;
uk_hlist_del(n);
@@ -317,7 +304,6 @@ uk_hlist_del_init(struct uk_hlist_node *n)
static inline void
uk_hlist_add_head(struct uk_hlist_node *n, struct uk_hlist_head *h)
{
-
n->next = h->first;
if (h->first != NULL)
h->first->pprev = &n->next;
@@ -328,7 +314,6 @@ uk_hlist_add_head(struct uk_hlist_node *n, struct
uk_hlist_head *h)
static inline void
uk_hlist_add_before(struct uk_hlist_node *n, struct uk_hlist_node *next)
{
-
n->pprev = next->pprev;
n->next = next;
next->pprev = &n->next;
@@ -338,7 +323,6 @@ uk_hlist_add_before(struct uk_hlist_node *n, struct
uk_hlist_node *next)
static inline void
uk_hlist_add_behind(struct uk_hlist_node *n, struct uk_hlist_node *prev)
{
-
n->next = prev->next;
UK_WRITE_ONCE(prev->next, n);
n->pprev = &prev->next;
@@ -350,7 +334,6 @@ uk_hlist_add_behind(struct uk_hlist_node *n, struct
uk_hlist_node *prev)
static inline void
uk_hlist_move_list(struct uk_hlist_head *old, struct uk_hlist_head *new)
{
-
new->first = old->first;
if (new->first)
new->first->pprev = &new->first;
@@ -366,6 +349,7 @@ static inline void __uk_list_cut_position(struct
uk_list_head *list,
struct uk_list_head *head, struct uk_list_head *entry)
{
struct uk_list_head *new_first = entry->next;
+
list->next = head->next;
list->next->prev = list;
list->prev = entry;
@@ -396,16 +380,16 @@ static inline int uk_list_is_last(const struct
uk_list_head *list,
#define uk_hlist_entry(ptr, type, field) __containerof(ptr, type, field)
-#define uk_hlist_for_each(p, head) \
+#define uk_hlist_for_each(p, head) \
for (p = (head)->first; p; p = (p)->next)
-#define uk_hlist_for_each_safe(p, n, head) \
+#define uk_hlist_for_each_safe(p, n, head)
\
for (p = (head)->first; p && ({ n = (p)->next; 1; }); p = n)
#define uk_hlist_entry_safe(ptr, type, member) \
((ptr) ? uk_hlist_entry(ptr, type, member) : NULL)
-#define uk_hlist_for_each_entry(pos, head, member) \
+#define uk_hlist_for_each_entry(pos, head, member)
\
for (pos = uk_hlist_entry_safe((head)->first, typeof(*(pos)), member);\
pos; \
pos = uk_hlist_entry_safe((pos)->member.next, typeof(*(pos)),
member))
@@ -415,17 +399,19 @@ static inline int uk_list_is_last(const struct
uk_list_head *list,
(pos); \
pos = uk_hlist_entry_safe((pos)->member.next, typeof(*(pos)),
member))
-#define uk_hlist_for_each_entry_from(pos, member) \
- for (; (pos);
\
+#define uk_hlist_for_each_entry_from(pos, member)
\
+ for (; (pos); \
pos = uk_hlist_entry_safe((pos)->member.next, typeof(*(pos)),
member))
-#define uk_hlist_for_each_entry_safe(pos, n, head, member) \
+#define uk_hlist_for_each_entry_safe(pos, n, head, member)
\
for (pos = uk_hlist_entry_safe((head)->first, typeof(*(pos)), member); \
(pos) && ({ n = (pos)->member.next; 1; }); \
pos = uk_hlist_entry_safe(n, typeof(*(pos)), member))
-extern void list_sort(void *priv, struct uk_list_head *head, int (*cmp)(void *priv,
- struct uk_list_head *a, struct uk_list_head *b));
+extern void list_sort(void *priv, struct uk_list_head *head,
+ int (*cmp)(void *priv,
+ struct uk_list_head *a,
+ struct uk_list_head *b));
/* TODO: get rid of the old linked list implementation */
#include <uk/compat_list.h>