Update implementation of thread set priority to account for donations, w/ T
This commit is contained in:
@@ -370,20 +370,34 @@ priority_more (const struct list_elem *a_, const struct list_elem *b_,
|
|||||||
return a->priority > b->priority;
|
return a->priority > b->priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets the current thread's priority to NEW_PRIORITY. */
|
/* Sets the current thread's base priority to new_base_priority.
|
||||||
|
Updates the current thread's effective priority if necessary. */
|
||||||
void
|
void
|
||||||
thread_set_priority (int new_priority)
|
thread_set_priority (int new_base_priority)
|
||||||
{
|
{
|
||||||
ASSERT (new_priority >= PRI_MIN);
|
ASSERT (new_base_priority >= PRI_MIN);
|
||||||
ASSERT (new_priority <= PRI_MAX);
|
ASSERT (new_base_priority <= PRI_MAX);
|
||||||
|
|
||||||
|
struct thread *t = thread_current ();
|
||||||
|
|
||||||
|
int old_base_priority = t->base_priority;
|
||||||
int old_priority = thread_get_priority ();
|
int old_priority = thread_get_priority ();
|
||||||
if (new_priority == old_priority)
|
if (new_base_priority == old_base_priority)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
thread_current ()->priority = new_priority;
|
|
||||||
|
|
||||||
if (new_priority < old_priority && !list_empty (&ready_list))
|
t->base_priority = new_base_priority;
|
||||||
|
t->priority = new_base_priority;
|
||||||
|
|
||||||
|
if (!list_empty (&t->donors_list) && new_base_priority < old_priority) {
|
||||||
|
int max_donated_priority =
|
||||||
|
list_entry (list_max (&t->donors_list, priority_more, NULL),
|
||||||
|
struct thread, donor_elem)->priority;
|
||||||
|
|
||||||
|
if(new_base_priority < max_donated_priority)
|
||||||
|
t->priority = new_base_priority;
|
||||||
|
}
|
||||||
|
|
||||||
thread_yield ();
|
thread_yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user