From ebc6facfe38c81e0ab236bd1d7d95c5314e966be Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 3 Nov 2004 23:31:55 +0000 Subject: [PATCH] Patch to make bitmap choice random. --- grading/userprog/random.diff | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 grading/userprog/random.diff diff --git a/grading/userprog/random.diff b/grading/userprog/random.diff new file mode 100644 index 0000000..bbc1541 --- /dev/null +++ b/grading/userprog/random.diff @@ -0,0 +1,37 @@ +--- bitmap.c.~1.5.~ 2004-10-06 14:29:56.000000000 -0700 ++++ bitmap.c 2004-11-03 14:35:22.000000000 -0800 +@@ -1,6 +1,7 @@ + #include "bitmap.h" + #include + #include ++#include + #include + #include + #include "threads/malloc.h" +@@ -212,14 +213,25 @@ size_t + bitmap_scan (const struct bitmap *b, size_t start, size_t cnt, bool value) + { + size_t idx, last; ++ size_t n = 0, m; + + ASSERT (b != NULL); + ASSERT (start <= b->bit_cnt); + + for (idx = start, last = b->bit_cnt - cnt; idx <= last; idx++) + if (!contains (b, idx, idx + cnt, !value)) ++ n++; ++ if (n == 0) ++ return BITMAP_ERROR; ++ ++ random_init (0); ++ m = random_ulong () % n; ++ ++ for (idx = start, last = b->bit_cnt - cnt; idx <= last; idx++) ++ if (!contains (b, idx, idx + cnt, !value) && m-- == 0) + return idx; +- return BITMAP_ERROR; ++ ++ NOT_REACHED (); + } + + /* Finds the first group of CNT consecutive bits in B at or after -- 2.30.2