Merge complete code base into master #15

Merged
ed1223 merged 4 commits from merged-complete into master 2024-10-23 19:05:46 +00:00
2 changed files with 72 additions and 74 deletions
Showing only changes of commit d8c843f16a - Show all commits

View File

@@ -251,19 +251,27 @@ lock_acquire (struct lock *lock)
ASSERT (!lock_held_by_current_thread (lock)); ASSERT (!lock_held_by_current_thread (lock));
struct thread *t = thread_current (); struct thread *t = thread_current ();
enum intr_level old_level = intr_disable ();
if (lock->holder != NULL) if(!thread_mlfqs)
{ {
t->waiting_lock = lock;
donate_priority (lock->holder); enum intr_level old_level = intr_disable ();
}
if (lock->holder != NULL)
{
t->waiting_lock = lock;
donate_priority (lock->holder);
}
intr_set_level (old_level);
}
intr_set_level (old_level);
sema_down (&lock->semaphore); sema_down (&lock->semaphore);
lock->holder = thread_current (); lock->holder = thread_current ();
t->waiting_lock = NULL; if (!thread_mlfqs)
t->waiting_lock = NULL;
} }
/* Tries to acquires LOCK and returns true if successful or false /* Tries to acquires LOCK and returns true if successful or false
@@ -297,50 +305,53 @@ lock_release (struct lock *lock)
ASSERT (lock != NULL); ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock)); ASSERT (lock_held_by_current_thread (lock));
struct thread *current_thread = thread_current (); if (!thread_mlfqs)
struct thread *max_donor = NULL; {
struct thread *current_thread = thread_current ();
struct thread *max_donor = NULL;
struct list orphan_list; struct list orphan_list;
list_init (&orphan_list); list_init (&orphan_list);
enum intr_level old_level = intr_disable (); enum intr_level old_level = intr_disable ();
/* Loop through current thread's donors, removing the ones waiting for the /* Loop through current thread's donors, removing the ones waiting for the
lock being released and keeping track of them (within orphan_list). lock being released and keeping track of them (within orphan_list).
Also identifies the highest priority donor thread among them. */ Also identifies the highest priority donor thread among them. */
struct list_elem *tail = list_tail (&current_thread->donors_list); struct list_elem *tail = list_tail (&current_thread->donors_list);
struct list_elem *e = list_begin (&current_thread->donors_list); struct list_elem *e = list_begin (&current_thread->donors_list);
while (e != tail) while (e != tail)
{ {
struct thread *donor = list_entry (e, struct thread, donor_elem); struct thread *donor = list_entry (e, struct thread, donor_elem);
struct list_elem *next = list_next (e); struct list_elem *next = list_next (e);
/* Excludes donors that aren't waiting for the lock being released, /* Excludes donors that aren't waiting for the lock being released,
and tracks the rest. */ and tracks the rest. */
if (donor->waiting_lock == lock) if (donor->waiting_lock == lock)
{ {
list_remove (e); list_remove (e);
list_push_back (&orphan_list, e); list_push_back (&orphan_list, e);
/* Identify highest priority donor. */ /* Identify highest priority donor. */
if (max_donor == NULL || donor->priority > max_donor->priority) if (max_donor == NULL || donor->priority > max_donor->priority)
max_donor = donor; max_donor = donor;
} }
e = next; e = next;
} }
/* If there exists a maximum donor thread waiting for this lock to be /* If there exists a maximum donor thread waiting for this lock to be
released, transfer the remaining orphaned donors to its donor list. */ released, transfer the remaining orphaned donors to its donor list. */
if (max_donor != NULL) if (max_donor != NULL)
{ {
while (!list_empty (&orphan_list)) while (!list_empty (&orphan_list))
list_push_back (&max_donor->donors_list, list_pop_front (&orphan_list)); list_push_back (&max_donor->donors_list, list_pop_front (&orphan_list));
} }
intr_set_level (old_level); intr_set_level (old_level);
/* Removal of donors to this thread may change its effective priority, /* Removal of donors to this thread may change its effective priority,
so recalculate. */ so recalculate. */
thread_recalculate_priority (); thread_recalculate_priority ();
}
lock->holder = NULL; lock->holder = NULL;
sema_up (&lock->semaphore); sema_up (&lock->semaphore);

View File

@@ -474,6 +474,12 @@ thread_recalculate_priority (void)
{ {
struct thread *t = thread_current (); struct thread *t = thread_current ();
if (thread_mlfqs)
{
t->priority = calculate_bsd_priority (t->recent_cpu, t->nice);
return;
}
enum intr_level old_level = intr_disable (); enum intr_level old_level = intr_disable ();
t->priority = t->base_priority; t->priority = t->base_priority;