X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fkernel%2Flist.c;h=ba4fae68bfe51919dc30a43007f634c2fa8d0474;hb=0ec49949304b13ff22287d7d9e3dcb05090c61a4;hp=1227d6b6b5679f5c2708af027e0a69241684d613;hpb=62e4f39fca59b2ff84fc0ae8e74240cb9941b3ec;p=pintos-anon diff --git a/src/lib/kernel/list.c b/src/lib/kernel/list.c index 1227d6b..ba4fae6 100644 --- a/src/lib/kernel/list.c +++ b/src/lib/kernel/list.c @@ -216,15 +216,15 @@ list_push_back (struct list *list, list_elem *elem) list_insert (list_end (list), elem); } -/* Removes ELEM from its list. Undefined behavior if ELEM is not - in a list. */ +/* Removes ELEM from its list and returns the element that + followed it. Undefined behavior if ELEM is not in a list. */ list_elem * list_remove (list_elem *elem) { ASSERT (is_interior (elem)); elem->prev->next = elem->next; elem->next->prev = elem->prev; - return elem; + return elem->next; } /* Removes the front element from LIST and returns it. @@ -232,8 +232,9 @@ list_remove (list_elem *elem) list_elem * list_pop_front (struct list *list) { - ASSERT (list != NULL); - return list_remove (list_front (list)); + list_elem *front = list_front (list); + list_remove (front); + return front; } /* Removes the back element from LIST and returns it. @@ -241,8 +242,9 @@ list_pop_front (struct list *list) list_elem * list_pop_back (struct list *list) { - ASSERT (list != NULL); - return list_remove (list_back (list)); + list_elem *back = list_back (list); + list_remove (back); + return back; } /* Returns the front element in LIST.