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, head) \
7 for (pos = (head)->first; pos; pos = (pos)->next)
9 #define wq_list_for_each(pos, prv, head) \
10 for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
12 #define wq_list_for_each_resume(pos, prv) \
13 for (; pos; prv = pos, pos = (pos)->next)
15 #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
17 #define INIT_WQ_LIST(list) do { \
18 (list)->first = NULL; \
21 static inline void wq_list_add_after(struct io_wq_work_node *node,
22 struct io_wq_work_node *pos,
23 struct io_wq_work_list *list)
25 struct io_wq_work_node *next = pos->next;
33 static inline void wq_list_add_tail(struct io_wq_work_node *node,
34 struct io_wq_work_list *list)
39 WRITE_ONCE(list->first, node);
41 list->last->next = node;
46 static inline void wq_list_add_head(struct io_wq_work_node *node,
47 struct io_wq_work_list *list)
49 node->next = list->first;
52 WRITE_ONCE(list->first, node);
55 static inline void wq_list_cut(struct io_wq_work_list *list,
56 struct io_wq_work_node *last,
57 struct io_wq_work_node *prev)
59 /* first in the list, if prev==NULL */
61 WRITE_ONCE(list->first, last->next);
63 prev->next = last->next;
65 if (last == list->last)
70 static inline void __wq_list_splice(struct io_wq_work_list *list,
71 struct io_wq_work_node *to)
73 list->last->next = to->next;
74 to->next = list->first;
78 static inline bool wq_list_splice(struct io_wq_work_list *list,
79 struct io_wq_work_node *to)
81 if (!wq_list_empty(list)) {
82 __wq_list_splice(list, to);
88 static inline void wq_stack_add_head(struct io_wq_work_node *node,
89 struct io_wq_work_node *stack)
91 node->next = stack->next;
95 static inline void wq_list_del(struct io_wq_work_list *list,
96 struct io_wq_work_node *node,
97 struct io_wq_work_node *prev)
99 wq_list_cut(list, node, prev);
103 struct io_wq_work_node *wq_stack_extract(struct io_wq_work_node *stack)
105 struct io_wq_work_node *node = stack->next;
107 stack->next = node->next;
111 static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
113 if (!work->list.next)
116 return container_of(work->list.next, struct io_wq_work, list);
119 #endif // INTERNAL_IO_SLIST_H