xlist.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef _LINUX_XLIST_H
  2. #define _LINUX_XLIST_H
  3. #include <linux/stddef.h>
  4. #include <linux/poison.h>
  5. #include <linux/prefetch.h>
  6. #include <asm/system.h>
  7. struct xlist_head {
  8. struct xlist_head *next;
  9. };
  10. static inline void INIT_XLIST_HEAD(struct xlist_head *list)
  11. {
  12. list->next = NULL;
  13. }
  14. static inline int xlist_empty(struct xlist_head *head)
  15. {
  16. return head->next == NULL;
  17. }
  18. static inline void xlist_add(struct xlist_head *new, struct xlist_head *tail,
  19. struct xlist_head *head)
  20. {
  21. struct xlist_head *cur;
  22. struct xlist_head *check;
  23. while (1) {
  24. cur = head->next;
  25. tail->next = cur;
  26. check = cmpxchg(&head->next, cur, new);
  27. if (check == cur)
  28. break;
  29. }
  30. }
  31. static inline struct xlist_head *xlist_del_head(struct xlist_head *head)
  32. {
  33. struct xlist_head *cur;
  34. struct xlist_head *check;
  35. struct xlist_head *next;
  36. while (1) {
  37. cur = head->next;
  38. if (!cur)
  39. goto out;
  40. next = cur->next;
  41. check = cmpxchg(&head->next, cur, next);
  42. if (check == cur)
  43. goto out;
  44. }
  45. out:
  46. return cur;
  47. }
  48. static inline struct xlist_head *xlist_del_head_fast(struct xlist_head *head)
  49. {
  50. struct xlist_head *cur;
  51. cur = head->next;
  52. if (!cur)
  53. return NULL;
  54. head->next = cur->next;
  55. return cur;
  56. }
  57. static inline void xlist_splice(struct xlist_head *list,
  58. struct xlist_head *head)
  59. {
  60. struct xlist_head *cur;
  61. WARN_ON(head->next);
  62. cur = xchg(&list->next, NULL);
  63. head->next = cur;
  64. }
  65. #endif