Queue and list
This presentation is the property of its rightful owner.
Sponsored Links
1 / 8

Queue and List PowerPoint PPT Presentation


  • 69 Views
  • Uploaded on
  • Presentation posted in: General

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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

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

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 }


Queue and list

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

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

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

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

HLIST

structhlist_head {

structhlist_node *first;

};

structhlist_node {

structhlist_node *next, **pprev;

};


  • Login