X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Flib%2Fkernel%2Flist.h;h=82efbb5b1c19053a4b7c68723f358bb413ece4c2;hp=e71c1cab31500c801547ec39131ee668fdd8c288;hb=a03618133f7df0954802a470a4bee7674f7aed45;hpb=96c122af8890db8f39dfd2ee21df761c6131e8f5 diff --git a/src/lib/kernel/list.h b/src/lib/kernel/list.h index e71c1ca..82efbb5 100644 --- a/src/lib/kernel/list.h +++ b/src/lib/kernel/list.h @@ -105,8 +105,22 @@ struct list name of the outer structure STRUCT and the member name MEMBER of the list element. See the big comment at the top of the file for an example. */ -#define list_entry(LIST_ELEM, STRUCT, MEMBER) \ - ((STRUCT *) ((uint8_t *) (LIST_ELEM) - offsetof (STRUCT, MEMBER))) +#define list_entry(LIST_ELEM, STRUCT, MEMBER) \ + ((STRUCT *) ((uint8_t *) &(LIST_ELEM)->next \ + - offsetof (STRUCT, MEMBER.next))) + +/* List initialization. + + A list may be initialized by calling list_init(): + + struct list my_list; + list_init (&my_list); + + or with an initializer using LIST_INITIALIZER: + + struct list my_list = LIST_INITIALIZER (my_list); */ +#define LIST_INITIALIZER(NAME) { { NULL, &(NAME).tail }, \ + { &(NAME).head, NULL } } void list_init (struct list *); @@ -153,8 +167,6 @@ typedef bool list_less_func (const struct list_elem *a, void *aux); /* Operations on lists with ordered elements. */ -void list_merge (struct list *, struct list *, - list_less_func *, void *aux); void list_sort (struct list *, list_less_func *, void *aux); void list_insert_ordered (struct list *, struct list_elem *,