1 / 8

Queue and List

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.

Download Presentation

Queue and List

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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 }

  3. 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 }

  4. 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 }

  5. 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 }

  6. 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 }

  7. 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)

  8. HLIST structhlist_head { structhlist_node *first; }; structhlist_node { structhlist_node *next, **pprev; };

More Related