X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Fpalloc.c;fp=src%2Fthreads%2Fpalloc.c;h=2b07ad769c139ff3f7f661980936fbde0e6eea5e;hb=b413e78bacc4a0331191e581cd060281ba47c54a;hp=a25c09e0715d3140ff3f122f051aff0539693daa;hpb=349cc721b17effa62c8b18a7dccc5defc44472d3;p=pintos-anon diff --git a/src/threads/palloc.c b/src/threads/palloc.c index a25c09e..2b07ad7 100644 --- a/src/threads/palloc.c +++ b/src/threads/palloc.c @@ -58,6 +58,10 @@ palloc_init (void) list_init (&free_pages); } +/* Obtains and returns a free page. If PAL_ZERO is set in FLAGS, + then the page is filled with zeros. If no pages are + available, returns a null pointer, unless PAL_ASSERT is set in + FLAGS, in which case the kernel panics. */ void * palloc_get (enum palloc_flags flags) { @@ -65,6 +69,10 @@ palloc_get (enum palloc_flags flags) lock_acquire (&lock); + /* If there's a page in the free list, take it. + Otherwise, if there's a page not yet added to the free list, + use it. + Otherwise, we're out of memory. */ if (!list_empty (&free_pages)) page = list_entry (list_pop_front (&free_pages), struct page, free_elem); else if (uninit_start < uninit_end) @@ -91,6 +99,7 @@ palloc_get (enum palloc_flags flags) return page; } +/* Frees PAGE. */ void palloc_free (void *page_) {