Merge 'task1/priority-donation' into 'master' #14
@@ -188,7 +188,21 @@ lock_init (struct lock *lock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
donate_priority (struct thread *donor, struct thread *donee);
|
donate_priority (struct thread *donor, struct thread *donee) {
|
||||||
|
while (donee != NULL)
|
||||||
|
{
|
||||||
|
if (donor->priority <= donee->priority)
|
||||||
|
break;
|
||||||
|
|
||||||
|
donee->priority = donor->priority;
|
||||||
|
if (donee->waiting_lock == NULL)
|
||||||
|
donee = NULL;
|
||||||
|
else
|
||||||
|
donee = donee->waiting_lock->holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
ready_list_reorder ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Acquires LOCK, sleeping until it becomes available if
|
/* Acquires LOCK, sleeping until it becomes available if
|
||||||
necessary. The lock must not already be held by the current
|
necessary. The lock must not already be held by the current
|
||||||
|
|||||||
@@ -439,6 +439,12 @@ thread_get_recent_cpu (void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ready_list_reorder (void)
|
||||||
|
{
|
||||||
|
list_sort (&ready_list, priority_more, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Idle thread. Executes when no other thread is ready to run.
|
/* Idle thread. Executes when no other thread is ready to run.
|
||||||
|
|
||||||
The idle thread is initially put on the ready list by
|
The idle thread is initially put on the ready list by
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ void thread_set_nice (int);
|
|||||||
int thread_get_recent_cpu (void);
|
int thread_get_recent_cpu (void);
|
||||||
int thread_get_load_avg (void);
|
int thread_get_load_avg (void);
|
||||||
|
|
||||||
|
void ready_list_reorder (void);
|
||||||
|
|
||||||
/* Returns true iff the priority of the first list element's thread is greater
|
/* Returns true iff the priority of the first list element's thread is greater
|
||||||
than that of the second list element's thread. */
|
than that of the second list element's thread. */
|
||||||
list_less_func thread_priority_greater;
|
list_less_func thread_priority_greater;
|
||||||
|
|||||||
Reference in New Issue
Block a user