1 #ifndef INTERNAL_IO_SLIST_H
2 #define INTERNAL_IO_SLIST_H
4 #include <linux/io_uring_types.h>
6 #define wq_list_for_each(pos, prv, head) \
7 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
9 #define wq_list_for_each_resume(pos, prv) \
10 for (; pos; prv = pos, pos = (pos)->next)
12 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
14 #define INIT_WQ_LIST(list) do { \
15 (list)->first = NULL; \
18 static inline void wq_list_add_after(struct io_wq_work_node *node,
19 struct io_wq_work_node *pos,
20 struct io_wq_work_list *list)
22 struct io_wq_work_node *next = pos->next;
31 * wq_list_merge - merge the second list to the first one.
32 * @list0: the first list
33 * @list1: the second list
34 * Return the first node after mergence.
36 static inline struct io_wq_work_node *wq_list_merge(struct io_wq_work_list *list0,
37 struct io_wq_work_list *list1)
39 struct io_wq_work_node *ret;
45 list0->last->next = list1->first;
52 static inline void wq_list_add_tail(struct io_wq_work_node *node,
53 struct io_wq_work_list *list)
58 WRITE_ONCE(list->first, node);
60 list->last->next = node;
65 static inline void wq_list_add_head(struct io_wq_work_node *node,
66 struct io_wq_work_list *list)
68 node->next = list->first;
71 WRITE_ONCE(list->first, node);
74 static inline void wq_list_cut(struct io_wq_work_list *list,
75 struct io_wq_work_node *last,
76 struct io_wq_work_node *prev)
78 /* first in the list, if prev==NULL */
80 WRITE_ONCE(list->first, last->next);
82 prev->next = last->next;
84 if (last == list->last)
89 static inline void __wq_list_splice(struct io_wq_work_list *list,
90 struct io_wq_work_node *to)
92 list->last->next = to->next;
93 to->next = list->first;
97 static inline bool wq_list_splice(struct io_wq_work_list *list,
98 struct io_wq_work_node *to)
100 if (!wq_list_empty(list)) {
101 __wq_list_splice(list, to);
107 static inline void wq_stack_add_head(struct io_wq_work_node *node,
108 struct io_wq_work_node *stack)
110 node->next = stack->next;
114 static inline void wq_list_del(struct io_wq_work_list *list,
115 struct io_wq_work_node *node,
116 struct io_wq_work_node *prev)
118 wq_list_cut(list, node, prev);
122 struct io_wq_work_node *wq_stack_extract(struct io_wq_work_node *stack)
124 struct io_wq_work_node *node = stack->next;
126 stack->next = node->next;
130 static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
132 if (!work->list.next)
135 return container_of(work->list.next, struct io_wq_work, list);
138 #endif // INTERNAL_IO_SLIST_H