list.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef __EI_LIST_H__
  2. #define __EI_LIST_H__
  3. #ifndef _LINUX_LIST_H
  4. #define INIT_LIST_HEAD(ptr) \
  5. do { \
  6. (ptr)->next = (ptr); \
  7. (ptr)->prev = (ptr); \
  8. } while (0)
  9. #define LIST_HEAD_INIT(name) { &(name), &(name) }
  10. struct list_head {
  11. struct list_head *next, *prev;
  12. };
  13. static inline void __list_add(struct list_head *_new, struct list_head *prev,
  14. struct list_head *next)
  15. {
  16. next->prev = _new;
  17. _new->next = next;
  18. _new->prev = prev;
  19. prev->next = _new;
  20. }
  21. static inline void list_add(struct list_head *_new, struct list_head *head)
  22. {
  23. __list_add(_new, head, head->next);
  24. }
  25. static inline void list_add_tail(struct list_head *_new, struct list_head *head)
  26. {
  27. __list_add(_new, head->prev, head);
  28. }
  29. static inline void __list_del(struct list_head *prev, struct list_head *next)
  30. {
  31. next->prev = prev;
  32. prev->next = next;
  33. }
  34. static inline void list_del(struct list_head *entry)
  35. {
  36. __list_del(entry->prev, entry->next);
  37. }
  38. static inline void list_del_init(struct list_head *entry)
  39. {
  40. __list_del(entry->prev, entry->next);
  41. INIT_LIST_HEAD(entry);
  42. }
  43. static inline void list_move(struct list_head *list, struct list_head *head)
  44. {
  45. __list_del(list->prev, list->next);
  46. list_add(list, head);
  47. }
  48. static inline void list_move_tail(struct list_head *list,
  49. struct list_head *head)
  50. {
  51. __list_del(list->prev, list->next);
  52. list_add_tail(list, head);
  53. }
  54. static inline int list_empty(struct list_head *head)
  55. {
  56. return head->next == head;
  57. }
  58. static inline void __list_splice(struct list_head *list,
  59. struct list_head *head)
  60. {
  61. struct list_head *first = list->next;
  62. struct list_head *last = list->prev;
  63. struct list_head *at = head->next;
  64. first->prev = head;
  65. head->next = first;
  66. last->next = at;
  67. at->prev = last;
  68. }
  69. static inline void list_splice(struct list_head *list, struct list_head *head)
  70. {
  71. if (!list_empty(list)) {
  72. __list_splice(list, head);
  73. }
  74. }
  75. static inline void list_splice_init(struct list_head *list, struct list_head *head)
  76. {
  77. if (!list_empty(list)) {
  78. __list_splice(list, head);
  79. INIT_LIST_HEAD(list);
  80. }
  81. }
  82. #define list_entry(ptr, type, member) \
  83. ((type *)((unsigned long)(ptr)-((unsigned long)(&((type *)1)->member) - 1)))
  84. #define list_for_each(pos, head) \
  85. for (pos = (head)->next; pos != (head); pos = pos->next)
  86. #define list_for_each_safe(pos, n, head) \
  87. for (pos = (head)->next, n = pos->next; pos != (head); \
  88. pos = n, n = pos->next)
  89. #define get_first_item(attached, type, member) \
  90. ((type *)((char *)((attached)->next)-(unsigned long)(&((type *)0)->member)))
  91. #endif
  92. #endif