80 likes | 255 Views
Queue and List. Freebsd Type independent definition, get data structure directly SLIST, SLISTQ, LIST, TAILQ, CIRCLEQ Linux Embedded in data structure, get data structure by offset LIST_HEAD, HLIST. SLIST.
E N D
Queue and List • Freebsd • Type independent definition, get data structure directly • SLIST, SLISTQ, LIST, TAILQ, CIRCLEQ • Linux • Embedded in data structure, get data structure by offset • LIST_HEAD, HLIST
SLIST 140 #define SLIST_HEAD(name, type) \ 141 struct name { \ 142 struct type *slh_first; /* first element */ \ 143 } 148 #define SLIST_ENTRY(type) \ 149 struct { \ 150 struct type *sle_next; /* next element */ \ 151 }
STAILQ 211 #define STAILQ_HEAD(name, type) \ 212 struct name { \ 213 struct type *stqh_first;/* first element */ \ 214 struct type **stqh_last;/* addr of last next element */ \ 215 } Compare with new definition, the original one is easy to delete the last entry 220 #define STAILQ_ENTRY(type) \ 221 struct { \ 222 struct type *stqe_next; /* next element */ \ 223 } 211 #define STAILQ_HEAD(name, type) \ 212 struct name { \ 213 struct type *stqh_first;/* first element */ \ 214 struct type *stqh_last;/* addr of last next element */ \ 215 }
LIST 310 #define LIST_HEAD(name, type) \ 311 struct name { \ 312 struct type *lh_first; /* first element */ \ 313 } 318 #define LIST_ENTRY(type) \ 319 struct { \ 320 struct type *le_next; /* next element */ \ 321 struct type **le_prev; /* address of previous next element */ \ 322 } For original one, the first entry's le_prev points to header; for new definition, the first entry's le_prev points to NULL, it is hard to remove first entry because you do not know header 318 #define LIST_ENTRY(type) \ 319 struct { \ 320 struct type *le_next; /* next element */ \ 321 struct type *le_prev; /* address of previous next element */ \ 322 }
TQILQ 392 #define TAILQ_HEAD(name, type) \ 393 struct name { \ 394 struct type *tqh_first; /* first element */ \ 395 struct type **tqh_last; /* addr of last next element */ \ 396} 402 #define TAILQ_ENTRY(type) \ 403 struct { \ 404 struct type *tqe_next; /* next element */ \ 405 struct type **tqe_prev; /* address of previous next element */ \ 406 }
CIRCLEQ 418 #define CIRCLEQ_HEAD(name, type) \ 419 struct name { \ 420 struct type *cqh_first; /* first element */ \ 421 struct type *cqh_last; /* last element */ \ 422 } 427 #define CIRCLEQ_ENTRY(type) \ 428 struct { \ 429 struct type *cqe_next; /* next element */ \ 430 struct type *cqe_prev; /* previous element */ \ 431 }
LIST_HEAD structlist_head { structlist_head *next, *prev; }; #define list_entry(ptr, type, member) \ container_of(ptr, type, member) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
HLIST structhlist_head { structhlist_node *first; }; structhlist_node { structhlist_node *next, **pprev; };