refactor thread_mlfqs checks in synch.c
This commit is contained in:
@@ -305,8 +305,6 @@ lock_release (struct lock *lock)
|
||||
ASSERT (lock != NULL);
|
||||
ASSERT (lock_held_by_current_thread (lock));
|
||||
|
||||
if (!thread_mlfqs)
|
||||
{
|
||||
struct thread *current_thread = thread_current ();
|
||||
struct thread *max_donor = NULL;
|
||||
|
||||
@@ -351,7 +349,6 @@ lock_release (struct lock *lock)
|
||||
/* Removal of donors to this thread may change its effective priority,
|
||||
so recalculate. */
|
||||
thread_recalculate_priority ();
|
||||
}
|
||||
|
||||
lock->holder = NULL;
|
||||
sema_up (&lock->semaphore);
|
||||
|
||||
@@ -157,7 +157,14 @@ thread_tick (void)
|
||||
|
||||
/* Update system load_avg and all threads recent_cpu every second. */
|
||||
int64_t ticks = timer_ticks ();
|
||||
if (thread_mlfqs && (ticks % TIMER_FREQ == 0))
|
||||
if (thread_mlfqs)
|
||||
{
|
||||
if (t != idle_thread)
|
||||
{
|
||||
t->recent_cpu = fp_add_int (t->recent_cpu, 1);
|
||||
}
|
||||
|
||||
if (ticks % TIMER_FREQ == 0)
|
||||
{
|
||||
size_t ready = threads_ready ();
|
||||
if (t != idle_thread)
|
||||
@@ -169,11 +176,7 @@ thread_tick (void)
|
||||
thread_foreach (thread_update_recent_cpu, NULL);
|
||||
}
|
||||
|
||||
/* Update current thread's recent_cpu. */
|
||||
if (thread_mlfqs && (t != idle_thread))
|
||||
{
|
||||
t->recent_cpu = fp_add_int (t->recent_cpu, 1);
|
||||
if (ticks % 4 == 0) // recent_cpu was updated, update priority.
|
||||
if (ticks % TIME_SLICE == 0) // recent_cpu was updated, update priority.
|
||||
t->priority = calculate_bsd_priority (t->recent_cpu, t->nice);
|
||||
}
|
||||
|
||||
@@ -470,7 +473,8 @@ thread_recalculate_priority (void)
|
||||
{
|
||||
struct thread *t = thread_current ();
|
||||
|
||||
ASSERT(!thread_mlfqs)
|
||||
if (thread_mlfqs)
|
||||
return;
|
||||
|
||||
enum intr_level old_level = intr_disable ();
|
||||
t->priority = t->base_priority;
|
||||
|
||||
Reference in New Issue
Block a user