From 2ea82ff0203b1cc22b55900752d44514506eb01e Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 10 May 2012 12:04:50 +0200 Subject: * only wake up one thread in sema_up() and remove pre-sorting in sema_down() * some small code guideline fixes --- threads/thread.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'threads/thread.c') diff --git a/threads/thread.c b/threads/thread.c index a7db106..358d3a1 100644 --- a/threads/thread.c +++ b/threads/thread.c @@ -367,12 +367,12 @@ thread_set_priority (int new_priority) return; if (cur->is_donated) - { - cur->saved_priority = new_priority; - /* make sure we don't lower a donated priority */ - if (new_priority < cur->priority) - return; - } + { + cur->saved_priority = new_priority; + /* make sure we don't lower a donated priority */ + if (new_priority < cur->priority) + return; + } thread_other_set_priority (cur, new_priority); } @@ -387,18 +387,18 @@ thread_other_set_priority (struct thread *t, int new_priority) t->priority = new_priority; if (t->status == THREAD_READY) - { - /* sort our ordered list */ - list_remove (&t->elem); - list_insert_ordered (&ready_list, &t->elem, &thread_priority_cmp_greater, NULL); - } + { + /* sort our ordered list */ + list_remove (&t->elem); + list_insert_ordered (&ready_list, &t->elem, &thread_priority_cmp_greater, NULL); + } else if (t->status == THREAD_RUNNING && !list_empty (&ready_list)) - { - /* compare priority with the highest priority in the list */ - struct thread *t2 = list_entry (list_front (&ready_list), struct thread, elem); - if (t2->priority > t->priority) - thread_yield (); - } + { + /* compare priority with the highest priority in the list */ + struct thread *t2 = list_entry (list_front (&ready_list), struct thread, elem); + if (t2->priority > t->priority) + thread_yield (); + } } void @@ -413,21 +413,20 @@ thread_donate_priority (struct thread *donator, struct thread *donee) /* store our base priority */ if (!donee->is_donated) - { - donee->saved_priority = donee->priority; - donee->is_donated = true; - } + { + donee->saved_priority = donee->priority; + donee->is_donated = true; + } thread_other_set_priority (donee, donator->priority); } void thread_donation_pass_back (void) { - if (thread_current ()->is_donated) - { - thread_current ()->is_donated = false; - thread_set_priority (thread_current ()->saved_priority); - } + if (!thread_current ()->is_donated) + return; + thread_current ()->is_donated = false; + thread_set_priority (thread_current ()->saved_priority); } /* Returns the current thread's priority. */ -- cgit v1.2.3