X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Flib%2Fkernel%2Fbitmap.c;h=d323b8982e552c1dcc7ab385de78786b661aa36a;hp=77edf2270b35435538fbbb5adeec52096403f50b;hb=cd61e4747c8d597c302f0ef3f1b0a2b6ed5ce890;hpb=8008245440011d25307535c3bb6757eb72ae5abe diff --git a/src/lib/kernel/bitmap.c b/src/lib/kernel/bitmap.c index 77edf22..d323b89 100644 --- a/src/lib/kernel/bitmap.c +++ b/src/lib/kernel/bitmap.c @@ -1,7 +1,6 @@ #include "bitmap.h" #include #include -#include #include #include #include "threads/malloc.h" @@ -290,7 +289,7 @@ bitmap_all (const struct bitmap *b, size_t start, size_t cnt) /* Finding set or unset bits. */ -/* Finds and returns the starting index of a group of CNT +/* Finds and returns the starting index of the first group of CNT consecutive bits in B at or after START that are all set to VALUE. If there is no such group, returns BITMAP_ERROR. */ @@ -303,20 +302,15 @@ bitmap_scan (const struct bitmap *b, size_t start, size_t cnt, bool value) if (cnt <= b->bit_cnt) { size_t last = b->bit_cnt - cnt; - size_t middle = start + random_ulong () % (last - start + 1); - size_t i = middle; - do - { - if (!bitmap_contains (b, i, cnt, !value)) - return i; - i = i != last ? i + 1 : start; - } - while (i != middle); + size_t i; + for (i = start; i <= last; i++) + if (!bitmap_contains (b, i, cnt, !value)) + return i; } return BITMAP_ERROR; } -/* Finds a group of CNT consecutive bits in B at or after +/* Finds the first group of CNT consecutive bits in B at or after START that are all set to VALUE, flips them all to !VALUE, and returns the index of the first bit in the group. If there is no such group, returns BITMAP_ERROR.