add mlfqs condition checking in synchronisation primitives

This commit is contained in:
EDiasAlberto
2024-10-23 19:37:27 +01:00
parent 1fb101c365
commit d8c843f16a
2 changed files with 62 additions and 45 deletions

View File

@@ -251,6 +251,10 @@ lock_acquire (struct lock *lock)
ASSERT (!lock_held_by_current_thread (lock));
struct thread *t = thread_current ();
if(!thread_mlfqs)
{
enum intr_level old_level = intr_disable ();
if (lock->holder != NULL)
@@ -260,9 +264,13 @@ lock_acquire (struct lock *lock)
}
intr_set_level (old_level);
}
sema_down (&lock->semaphore);
lock->holder = thread_current ();
if (!thread_mlfqs)
t->waiting_lock = NULL;
}
@@ -297,6 +305,8 @@ 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;
@@ -341,6 +351,7 @@ 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);

View File

@@ -474,6 +474,12 @@ thread_recalculate_priority (void)
{
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 ();
t->priority = t->base_priority;