Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. typedef struct link
  3. {
  4.   struct link *prev;
  5.   struct link *next;
  6. }link_t;
  7.  
  8. #define LIST_INITIALIZE(name) \
  9.         link_t name = { .prev = &name, .next = &name }
  10.  
  11. #define list_get_instance(link, type, member) \
  12.   ((type *)(((u8_t *)(link)) - ((u8_t *)&(((type *)NULL)->member))))
  13.  
  14. static inline void link_initialize(link_t *link)
  15. {
  16.         link->prev = NULL;
  17.         link->next = NULL;
  18. }
  19.  
  20. static inline void list_initialize(link_t *head)
  21. {
  22.         head->prev = head;
  23.         head->next = head;
  24. }
  25.  
  26. static inline void list_append(link_t *link, link_t *head)
  27. {
  28.         link->prev = head->prev;
  29.         link->next = head;
  30.         head->prev->next = link;
  31.         head->prev = link;
  32. }
  33.  
  34. static inline void list_remove(link_t *link)
  35. {
  36.         link->next->prev = link->prev;
  37.         link->prev->next = link->next;
  38.         link_initialize(link);
  39. }
  40.  
  41. static inline Bool list_empty(link_t *head)
  42. {
  43.     return head->next == head ? TRUE : FALSE;
  44. }
  45.  
  46. static inline void list_prepend(link_t *link, link_t *head)
  47. {
  48.         link->next = head->next;
  49.         link->prev = head;
  50.         head->next->prev = link;
  51.         head->next = link;
  52. }
  53.  
  54. static inline list_insert(link_t *new, link_t *old)
  55. {
  56.    new->prev = old->prev;
  57.    new->next = old;
  58.    new->prev->next = new;
  59.    old->prev = new;
  60. }
  61.