From: Ben Pfaff Date: Thu, 26 Aug 2004 19:01:59 +0000 (+0000) Subject: Change list_elem from a struct to a typedef to make the hash table X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91d3ace5e59a1d435f9cbae9e9cef55dad55a27f;p=pintos-anon Change list_elem from a struct to a typedef to make the hash table implementation more straightforward. --- diff --git a/src/lib/list.c b/src/lib/list.c index fbdbca7..980c317 100644 --- a/src/lib/list.c +++ b/src/lib/list.c @@ -10,52 +10,52 @@ list_init (struct list *list) list->tail.next = NULL; } -struct list_elem * +list_elem * list_begin (struct list *list) { return list->head.next; } -struct list_elem * +list_elem * list_end (struct list *list) { return &list->tail; } static inline bool -is_head (struct list_elem *elem) +is_head (list_elem *elem) { return elem != NULL && elem->prev == NULL && elem->next != NULL; } static inline bool -is_real (struct list_elem *elem) +is_real (list_elem *elem) { return elem != NULL && elem->prev != NULL && elem->next != NULL; } static inline bool -is_tail (struct list_elem *elem) +is_tail (list_elem *elem) { return elem != NULL && elem->prev != NULL && elem->next == NULL; } -struct list_elem * -list_next (struct list_elem *elem) +list_elem * +list_next (list_elem *elem) { ASSERT (is_real (elem)); return elem->next; } -struct list_elem * -list_prev (struct list_elem *elem) +list_elem * +list_prev (list_elem *elem) { ASSERT (is_real (elem) || is_tail (elem)); return elem->prev; } void -list_insert (struct list_elem *before, struct list_elem *elem) +list_insert (list_elem *before, list_elem *elem) { ASSERT (is_real (before) || is_tail (before)); ASSERT (elem != NULL); @@ -67,8 +67,8 @@ list_insert (struct list_elem *before, struct list_elem *elem) } void -list_splice (struct list_elem *target, - struct list_elem *first, struct list_elem *last) +list_splice (list_elem *target, + list_elem *first, list_elem *last) { ASSERT (is_real (target) || is_tail (target)); if (first == last) @@ -90,19 +90,19 @@ list_splice (struct list_elem *target, } void -list_push_front (struct list *list, struct list_elem *elem) +list_push_front (struct list *list, list_elem *elem) { list_insert (list_begin (list), elem); } void -list_push_back (struct list *list, struct list_elem *elem) +list_push_back (struct list *list, list_elem *elem) { list_insert (list_end (list), elem); } -static struct list_elem * -remove_item (struct list_elem *elem) +static list_elem * +remove_item (list_elem *elem) { ASSERT (is_real (elem)); elem->prev->next = elem->next; @@ -111,30 +111,30 @@ remove_item (struct list_elem *elem) } void -list_remove (struct list_elem *elem) +list_remove (list_elem *elem) { remove_item (elem); } -struct list_elem * +list_elem * list_pop_front (struct list *list) { return remove_item (list_front (list)); } -struct list_elem * +list_elem * list_pop_back (struct list *list) { return remove_item (list_back (list)); } -struct list_elem * +list_elem * list_front (struct list *list) { return list_begin (list); } -struct list_elem * +list_elem * list_back (struct list *list) { return list_prev (list_end (list)); @@ -143,7 +143,7 @@ list_back (struct list *list) size_t list_size (struct list *list) { - struct list_elem *elem; + list_elem *elem; size_t cnt = 0; for (elem = list_begin (list); elem != list_end (list); elem = elem->next) @@ -160,12 +160,11 @@ list_empty (struct list *list) void list_reverse (struct list *list) { - struct list_elem *e; - struct list_elem te; + list_elem te, *e; for (e = &list->head; e != NULL; e = e->prev) { - struct list_elem *tep = e->prev; + list_elem *tep = e->prev; e->prev = e->next; e->next = tep; } @@ -179,7 +178,7 @@ void list_merge (struct list *al, struct list *bl, list_less_func *less, void *aux) { - struct list_elem *a; + list_elem *a; ASSERT (al != NULL); ASSERT (bl != NULL); @@ -188,7 +187,7 @@ list_merge (struct list *al, struct list *bl, a = list_begin (al); while (a != list_end (al)) { - struct list_elem *b = list_begin (bl); + list_elem *b = list_begin (bl); if (less (b, a, aux)) { list_splice (a, b, list_next (b)); @@ -206,7 +205,7 @@ list_sort (struct list *list, list_less_func *less, void *aux) { struct list tmp; - struct list_elem *middle, *last; + list_elem *middle, *last; ASSERT (list != NULL); ASSERT (less != NULL); @@ -236,10 +235,10 @@ list_sort (struct list *list, } void -list_insert_ordered (struct list *list, struct list_elem *elem, +list_insert_ordered (struct list *list, list_elem *elem, list_less_func *less, void *aux) { - struct list_elem *e; + list_elem *e; ASSERT (list != NULL); ASSERT (elem != NULL); @@ -255,7 +254,7 @@ void list_unique (struct list *list, list_less_func *less, void *aux) { - struct list_elem *elem, *next; + list_elem *elem, *next; ASSERT (list != NULL); ASSERT (less != NULL); diff --git a/src/lib/list.h b/src/lib/list.h index e5f86f9..25d94b3 100644 --- a/src/lib/list.h +++ b/src/lib/list.h @@ -5,14 +5,15 @@ #include #include -struct list_elem +typedef struct list_elem { struct list_elem *prev, *next; - }; + } +list_elem; struct list { - struct list_elem head, tail; + list_elem head, tail; }; #define list_entry(LIST_ELEM, STRUCT, MEMBER) \ @@ -20,37 +21,37 @@ struct list void list_init (struct list *); -struct list_elem *list_begin (struct list *); -struct list_elem *list_end (struct list *); -struct list_elem *list_next (struct list_elem *); -struct list_elem *list_prev (struct list_elem *); +list_elem *list_begin (struct list *); +list_elem *list_end (struct list *); +list_elem *list_next (list_elem *); +list_elem *list_prev (list_elem *); -void list_insert (struct list_elem *, struct list_elem *); -void list_splice (struct list_elem *before, - struct list_elem *first, struct list_elem *last); -void list_push_front (struct list *, struct list_elem *); -void list_push_back (struct list *, struct list_elem *); +void list_insert (list_elem *, list_elem *); +void list_splice (list_elem *before, + list_elem *first, list_elem *last); +void list_push_front (struct list *, list_elem *); +void list_push_back (struct list *, list_elem *); -void list_remove (struct list_elem *); -struct list_elem *list_pop_front (struct list *); -struct list_elem *list_pop_back (struct list *); +void list_remove (list_elem *); +list_elem *list_pop_front (struct list *); +list_elem *list_pop_back (struct list *); -struct list_elem *list_front (struct list *); -struct list_elem *list_back (struct list *); +list_elem *list_front (struct list *); +list_elem *list_back (struct list *); size_t list_size (struct list *); bool list_empty (struct list *); void list_reverse (struct list *); -typedef bool list_less_func (const struct list_elem *a, - const struct list_elem *b, void *aux); +typedef bool list_less_func (const list_elem *a, const list_elem *b, + void *aux); 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 *, +void list_insert_ordered (struct list *, list_elem *, list_less_func *, void *aux); void list_unique (struct list *, list_less_func *, void *aux); diff --git a/src/threads/synch.c b/src/threads/synch.c index 39e43c3..61446a1 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -7,7 +7,7 @@ /* One thread in a list. */ struct thread_elem { - struct list_elem elem; + list_elem elem; struct thread *thread; }; @@ -205,7 +205,7 @@ lock_name (const struct lock *lock) /* One semaphore in a list. */ struct semaphore_elem { - struct list_elem elem; + list_elem elem; struct semaphore semaphore; };