You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.2KB

  1. #ifndef _list_h_
  2. #define _list_h_
  3. struct list_head
  4. {
  5. struct list_head *next, *prev;
  6. };
  7. static inline void list_insert_after(struct list_head *item, struct list_head *head)
  8. {
  9. struct list_head *prev, *next;
  10. prev = head;
  11. next = head->next;
  12. item->prev = prev;
  13. item->next = next;
  14. next->prev = item;
  15. prev->next = item;
  16. }
  17. static inline void list_insert_before(struct list_head *item, struct list_head *head)
  18. {
  19. struct list_head *prev, *next;
  20. prev = head->prev;
  21. next = head;
  22. item->prev = prev;
  23. item->next = next;
  24. next->prev = item;
  25. prev->next = item;
  26. }
  27. static inline void list_remove(struct list_head *item)
  28. {
  29. struct list_head *prev, *next;
  30. prev = item->prev;
  31. next = item->next;
  32. prev->next = next;
  33. next->prev = prev;
  34. item->prev = item->next = 0;
  35. }
  36. static inline int list_empty(const struct list_head *head)
  37. {
  38. return head->next == head;
  39. }
  40. #define LIST_INIT_HEAD(list) do { (list)->next = (list)->prev = (list); } while (0)
  41. #define list_entry(ptr, type, member) \
  42. ((type*)((char*)ptr-(ptrdiff_t)(&((type*)0)->member)))
  43. #define list_for_each(pos, head) \
  44. for(pos = (head)->next; pos != (head); pos = pos->next)
  45. #define list_for_each_safe(pos, n, head) \
  46. for(pos = (head)->next, n = pos->next; pos != (head); pos = n, n=pos->next)
  47. #endif /* !_list_h_ */