slist.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef INTERNAL_IO_SLIST_H
  3. #define INTERNAL_IO_SLIST_H
  4. #include <linux/io_uring_types.h>
  5. #define __wq_list_for_each(pos, head) \
  6. for (pos = (head)->first; pos; pos = (pos)->next)
  7. #define wq_list_for_each(pos, prv, head) \
  8. for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
  9. #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
  10. #define INIT_WQ_LIST(list) do { \
  11. (list)->first = NULL; \
  12. } while (0)
  13. static inline void wq_list_add_after(struct io_wq_work_node *node,
  14. struct io_wq_work_node *pos,
  15. struct io_wq_work_list *list)
  16. {
  17. struct io_wq_work_node *next = pos->next;
  18. pos->next = node;
  19. node->next = next;
  20. if (!next)
  21. list->last = node;
  22. }
  23. static inline void wq_list_add_tail(struct io_wq_work_node *node,
  24. struct io_wq_work_list *list)
  25. {
  26. node->next = NULL;
  27. if (!list->first) {
  28. list->last = node;
  29. WRITE_ONCE(list->first, node);
  30. } else {
  31. list->last->next = node;
  32. list->last = node;
  33. }
  34. }
  35. static inline void wq_list_cut(struct io_wq_work_list *list,
  36. struct io_wq_work_node *last,
  37. struct io_wq_work_node *prev)
  38. {
  39. /* first in the list, if prev==NULL */
  40. if (!prev)
  41. WRITE_ONCE(list->first, last->next);
  42. else
  43. prev->next = last->next;
  44. if (last == list->last)
  45. list->last = prev;
  46. last->next = NULL;
  47. }
  48. static inline void wq_stack_add_head(struct io_wq_work_node *node,
  49. struct io_wq_work_node *stack)
  50. {
  51. node->next = stack->next;
  52. stack->next = node;
  53. }
  54. static inline void wq_list_del(struct io_wq_work_list *list,
  55. struct io_wq_work_node *node,
  56. struct io_wq_work_node *prev)
  57. {
  58. wq_list_cut(list, node, prev);
  59. }
  60. static inline
  61. struct io_wq_work_node *wq_stack_extract(struct io_wq_work_node *stack)
  62. {
  63. struct io_wq_work_node *node = stack->next;
  64. stack->next = node->next;
  65. return node;
  66. }
  67. static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
  68. {
  69. if (!work->list.next)
  70. return NULL;
  71. return container_of(work->list.next, struct io_wq_work, list);
  72. }
  73. #endif // INTERNAL_IO_SLIST_H