slist.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef INTERNAL_IO_SLIST_H
  2. #define INTERNAL_IO_SLIST_H
  3. #include <linux/io_uring_types.h>
  4. #define __wq_list_for_each(pos, head) \
  5. for (pos = (head)->first; pos; pos = (pos)->next)
  6. #define wq_list_for_each(pos, prv, head) \
  7. for (pos = (head)->first, prv = NULL; pos; prv = pos, pos = (pos)->next)
  8. #define wq_list_for_each_resume(pos, prv) \
  9. for (; pos; prv = pos, pos = (pos)->next)
  10. #define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
  11. #define INIT_WQ_LIST(list) do { \
  12. (list)->first = NULL; \
  13. } while (0)
  14. static inline void wq_list_add_after(struct io_wq_work_node *node,
  15. struct io_wq_work_node *pos,
  16. struct io_wq_work_list *list)
  17. {
  18. struct io_wq_work_node *next = pos->next;
  19. pos->next = node;
  20. node->next = next;
  21. if (!next)
  22. list->last = node;
  23. }
  24. static inline void wq_list_add_tail(struct io_wq_work_node *node,
  25. struct io_wq_work_list *list)
  26. {
  27. node->next = NULL;
  28. if (!list->first) {
  29. list->last = node;
  30. WRITE_ONCE(list->first, node);
  31. } else {
  32. list->last->next = node;
  33. list->last = node;
  34. }
  35. }
  36. static inline void wq_list_add_head(struct io_wq_work_node *node,
  37. struct io_wq_work_list *list)
  38. {
  39. node->next = list->first;
  40. if (!node->next)
  41. list->last = node;
  42. WRITE_ONCE(list->first, node);
  43. }
  44. static inline void wq_list_cut(struct io_wq_work_list *list,
  45. struct io_wq_work_node *last,
  46. struct io_wq_work_node *prev)
  47. {
  48. /* first in the list, if prev==NULL */
  49. if (!prev)
  50. WRITE_ONCE(list->first, last->next);
  51. else
  52. prev->next = last->next;
  53. if (last == list->last)
  54. list->last = prev;
  55. last->next = NULL;
  56. }
  57. static inline void __wq_list_splice(struct io_wq_work_list *list,
  58. struct io_wq_work_node *to)
  59. {
  60. list->last->next = to->next;
  61. to->next = list->first;
  62. INIT_WQ_LIST(list);
  63. }
  64. static inline bool wq_list_splice(struct io_wq_work_list *list,
  65. struct io_wq_work_node *to)
  66. {
  67. if (!wq_list_empty(list)) {
  68. __wq_list_splice(list, to);
  69. return true;
  70. }
  71. return false;
  72. }
  73. static inline void wq_stack_add_head(struct io_wq_work_node *node,
  74. struct io_wq_work_node *stack)
  75. {
  76. node->next = stack->next;
  77. stack->next = node;
  78. }
  79. static inline void wq_list_del(struct io_wq_work_list *list,
  80. struct io_wq_work_node *node,
  81. struct io_wq_work_node *prev)
  82. {
  83. wq_list_cut(list, node, prev);
  84. }
  85. static inline
  86. struct io_wq_work_node *wq_stack_extract(struct io_wq_work_node *stack)
  87. {
  88. struct io_wq_work_node *node = stack->next;
  89. stack->next = node->next;
  90. return node;
  91. }
  92. static inline struct io_wq_work *wq_next_work(struct io_wq_work *work)
  93. {
  94. if (!work->list.next)
  95. return NULL;
  96. return container_of(work->list.next, struct io_wq_work, list);
  97. }
  98. #endif // INTERNAL_IO_SLIST_H