Home | History | Annotate | Download | only in include
      1 
      2 #ifndef _DBLLISTS_H
      3 #define _DBLLISTS_H
      4 
      5 
      6 
      7 #define DBL_LIST_HEAD_INIT(name)        { &(name), &(name) }
      8 
      9 #define DBL_LIST_HEAD(name)             struct list_head name = DBL_LIST_HEAD_INIT(name)
     10 
     11 #define DBL_INIT_LIST_HEAD(ptr) \
     12 do { \
     13     (ptr)->pNext = (ptr)->pPrev = (ptr); \
     14 } while (0)
     15 
     16 #define DBL_LIST_ADD(newi, prev, next) \
     17 do { \
     18     struct list_head *pPrev = prev; \
     19     struct list_head *pNext = next; \
     20     (pNext)->pPrev = newi; \
     21     (newi)->pNext = pNext; \
     22     (newi)->pPrev = pPrev; \
     23     (pPrev)->pNext = newi; \
     24 } while (0)
     25 
     26 #define DBL_LIST_ADDH(new, head)        DBL_LIST_ADD(new, head, (head)->pNext)
     27 
     28 #define DBL_LIST_ADDT(new, head)        DBL_LIST_ADD(new, (head)->pPrev, head)
     29 
     30 #define DBL_LIST_UNLINK(prev, next) \
     31 do { \
     32     struct list_head *pPrev = prev; \
     33     struct list_head *pNext = next; \
     34     (next)->pPrev = pPrev; \
     35     (prev)->pNext = pNext; \
     36 } while (0)
     37 
     38 #define DBL_LIST_DEL(entry) \
     39 do { \
     40     DBL_LIST_UNLINK((entry)->pPrev, (entry)->pNext); \
     41     DBL_INIT_LIST_HEAD(entry); \
     42 } while (0)
     43 
     44 #define DBL_LIST_EMTPY(head)            ((head)->pNext == head)
     45 
     46 #define DBL_LIST_SPLICE(list, head) \
     47 do { \
     48     struct list_head *    first = (list)->pNext; \
     49     if (first != list) { \
     50         struct list_head *	last = (list)->pPrev; \
     51         struct list_head *	at = (head)->pNext; \
     52         (first)->pPrev = head; \
     53         (head)->pNext = first; \
     54         (last)->pNext = at; \
     55         (at)->pPrev = last; \
     56     } \
     57 } while (0)
     58 
     59 #define DBL_HEAD_COPY(oldh, newh) \
     60 do { \
     61     *(oldh) = (*newh); \
     62     (newh)->pNext->pPrev = (oldh); \
     63     (newh)->pPrev->pNext = (oldh); \
     64 } while (0)
     65 
     66 #define DBL_ITEM_IN_LIST(ptr)           (((ptr)->pPrev != (ptr)) && ((ptr)->pNext != (ptr)))
     67 
     68 #define DBL_LIST_FIRST(head)            (((head)->pNext != (head)) ? (head)->pNext: NULL)
     69 
     70 #define DBL_LIST_LAST(head)             (((head)->pPrev != (head)) ? (head)->pPrev: NULL)
     71 
     72 #define DBL_LIST_ENTRY(ptr, type, member)   ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
     73 
     74 #define DBL_LIST_FOR_EACH(pos, head)    for (pos = (head)->pNext; pos != (head); pos = (pos)->pNext)
     75 
     76 #define DBL_END_OF_LIST(pos, head)      ((pos) == (head))
     77 
     78 #define DBL_LIST_NEXT(pos, head)        (((pos)->pNext != (head)) ? (pos)->pNext: NULL)
     79 
     80 #define DBL_LIST_PREV(pos, head)        (((pos)->pPrev != (head)) ? (pos)->pPrev: NULL)
     81 
     82 
     83 
     84 
     85 
     86 
     87 
     88 struct list_head
     89 {
     90     struct list_head *pNext;
     91     struct list_head *pPrev;
     92 };
     93 
     94 
     95 
     96 
     97 
     98 #endif
     99