X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=solutions%2Fp1.patch;h=fbfb405b09a090df9889f5b279c6947c1a43756c;hb=f242d3f31c84c5a045b980b07745a364d7301a6d;hp=213e05ef29e2f749ab24ad6f5a38e02b7d0ca630;hpb=4ebf33908a571a7cde93fe618902b044e3633cdf;p=pintos-anon diff --git a/solutions/p1.patch b/solutions/p1.patch index 213e05e..fbfb405 100644 --- a/solutions/p1.patch +++ b/solutions/p1.patch @@ -236,10 +236,16 @@ diff -u src/threads/synch.c~ src/threads/synch.c intr_set_level (old_level); } -@@ -200,6 +218,23 @@ lock_acquire (struct lock *lock) +@@ -200,8 +218,29 @@ lock_acquire (struct lock *lock) + lock_acquire (struct lock *lock) + { ++ enum intr_level old_level; ++ + ASSERT (lock != NULL); + ASSERT (!intr_context ()); ASSERT (!lock_held_by_current_thread (lock)); - old_level = intr_disable (); ++ old_level = intr_disable (); + + if (lock->holder != NULL) + { @@ -259,18 +265,18 @@ diff -u src/threads/synch.c~ src/threads/synch.c + sema_down (&lock->semaphore); lock->holder = thread_current (); - intr_set_level (old_level); -@@ -238,13 +273,37 @@ void ++ intr_set_level (old_level); +@@ -238,9 +273,37 @@ void lock_release (struct lock *lock) { - enum intr_level old_level; ++ enum intr_level old_level; + struct thread *t = thread_current (); + struct list_elem *e; - ++ ASSERT (lock != NULL); ASSERT (lock_held_by_current_thread (lock)); - old_level = intr_disable (); ++ old_level = intr_disable (); + + /* Return donations to threads that want this lock. */ + for (e = list_begin (&t->donors); e != list_end (&t->donors); ) @@ -295,7 +301,7 @@ diff -u src/threads/synch.c~ src/threads/synch.c + thread_recompute_priority (t); + thread_yield_to_higher_priority (); + - intr_set_level (old_level); ++ intr_set_level (old_level); } @@ -264,6 +323,7 @@ struct semaphore_elem @@ -327,7 +333,7 @@ diff -u src/threads/synch.c~ src/threads/synch.c + const struct semaphore_elem *b + = list_entry (b_, struct semaphore_elem, elem); + -+ return a->thread->priority > b->thread->priority; ++ return a->thread->priority < b->thread->priority; +} + /* If any threads are waiting on COND (protected by LOCK), then @@ -358,11 +364,11 @@ diff -u src/threads/thread.c~ src/threads/thread.c +#include "threads/init.h" #include "threads/interrupt.h" #include "threads/intr-stubs.h" - #include "threads/mmu.h" #include "threads/palloc.h" #include "threads/switch.h" #include "threads/synch.h" +#include "devices/timer.h" + #include "threads/vaddr.h" #ifdef USERPROG #include "userprog/process.h" #endif @@ -488,7 +494,7 @@ diff -u src/threads/thread.c~ src/threads/thread.c + /* Add to run queue. */ thread_unblock (t); -+ if (priority < thread_get_priority ()) ++ if (priority > thread_get_priority ()) + thread_yield (); return tid; @@ -507,7 +513,7 @@ diff -u src/threads/thread.c~ src/threads/thread.c + const struct thread *a = list_entry (a_, struct thread, elem); + const struct thread *b = list_entry (b_, struct thread, elem); + -+ return a->priority > b->priority; ++ return a->priority < b->priority; +} + /* Transitions a blocked thread T to the ready-to-run state. @@ -608,7 +614,7 @@ diff -u src/threads/thread.c~ src/threads/thread.c + const struct thread *a = list_entry (a_, struct thread, donor_elem); + const struct thread *b = list_entry (b_, struct thread, donor_elem); + -+ return a->priority > b->priority; ++ return a->priority < b->priority; +} + +/* Recomputes T's priority in terms of its normal priority and @@ -619,10 +625,10 @@ diff -u src/threads/thread.c~ src/threads/thread.c +{ + int old_priority = t->priority; + int default_priority = t->normal_priority; -+ int donation = PRI_MAX; ++ int donation = PRI_MIN; + if (enable_mlfqs) + { -+ default_priority = fix_round (t->recent_cpu) / 4 + t->nice * 2; ++ default_priority = PRI_MAX - fix_round (t->recent_cpu) / 4 - t->nice * 2; + if (default_priority < PRI_MIN) + default_priority = PRI_MIN; + else if (default_priority > PRI_MAX) @@ -631,8 +637,8 @@ diff -u src/threads/thread.c~ src/threads/thread.c + if (!list_empty (&t->donors)) + donation = list_entry (list_max (&t->donors, donated_lower_priority, NULL), + struct thread, donor_elem)->priority; -+ t->priority = donation < default_priority ? donation : default_priority; -+ if (t->priority < old_priority && t->donee != NULL) ++ t->priority = donation > default_priority ? donation : default_priority; ++ if (t->priority > old_priority && t->donee != NULL) + thread_recompute_priority (t->donee); +} + @@ -648,7 +654,7 @@ diff -u src/threads/thread.c~ src/threads/thread.c + struct thread *max = list_entry (list_max (&ready_list, + thread_lower_priority, NULL), + struct thread, elem); -+ if (max->priority < cur->priority) ++ if (max->priority > cur->priority) + thread_yield (); + } + intr_set_level (old_level);