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.

list.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef LIST_H
  2. #define LIST_H
  3. /* from linux kernel */
  4. #define container_of(ptr, type, member) ({ \
  5. const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  6. (type *)( (char *)__mptr - offsetof(type,member) );})
  7. /**
  8. * list_entry - get the struct for this entry
  9. * @ptr: the &struct list_head pointer.
  10. * @type: the type of the struct this is embedded in.
  11. * @member: the name of the list_struct within the struct.
  12. */
  13. #define list_entry(ptr, type, member) container_of(ptr, type, member)
  14. void alloc_things(void);
  15. void *_allocentry(size_t size);
  16. #define allocentry(type) (type*) _allocentry(sizeof(type))
  17. void freeentry(void *ptr);
  18. void list_add_tail(listhead *header, listhead *entry);
  19. #define addtail(head, entry) list_add_tail(head, &(entry->list));
  20. /* remove entry from list */
  21. void list_del(listhead *entry);
  22. #define removeitem(entry) list_del(&(entry->list));
  23. void list_init_head(listhead *head);
  24. void things_list_clear(listhead *head); /* listhead member must be the first member */
  25. /**
  26. * list_for_each_entry - iterate over list of given type
  27. * @pos: the type * to use as a loop cursor.
  28. * @head: the head for your list.
  29. * @member: the name of the list_struct within the struct.
  30. */
  31. #define list_for_each_entry(pos, head, member) \
  32. for (pos = list_entry((head)->next, typeof(*pos), member); \
  33. /* prefetch(pos->member.next), */ \
  34. &pos->member != (head); \
  35. pos = list_entry(pos->member.next, typeof(*pos), member))
  36. /**
  37. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  38. * @pos:<-->the type * to use as a loop cursor.
  39. * @n:<><-->another type * to use as temporary storage
  40. * @head:<->the head for your list.
  41. * @member:>the name of the list_struct within the struct.
  42. */
  43. #define list_for_each_entry_safe(pos, n, head, member) \
  44. for (pos = list_entry((head)->next, typeof(*pos), member), \
  45. n = list_entry(pos->member.next, typeof(*pos), member); \
  46. &pos->member != (head); \
  47. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  48. #define list_empty(head) ((head) == (head)->next)
  49. #endif