Merge branch 'task1/saleh/priority-donation-refactoring' into 'master'
priority donation refactoring See merge request lab2425_autumn/pintos_22!20
This commit is contained in:
@@ -32,6 +32,10 @@
|
|||||||
#include "threads/interrupt.h"
|
#include "threads/interrupt.h"
|
||||||
#include "threads/thread.h"
|
#include "threads/thread.h"
|
||||||
|
|
||||||
|
static bool
|
||||||
|
priority_less (const struct list_elem *a_, const struct list_elem *b_,
|
||||||
|
void *aux UNUSED);
|
||||||
|
|
||||||
/* Initializes semaphore SEMA to VALUE. A semaphore is a
|
/* Initializes semaphore SEMA to VALUE. A semaphore is a
|
||||||
nonnegative integer along with two atomic operators for
|
nonnegative integer along with two atomic operators for
|
||||||
manipulating it:
|
manipulating it:
|
||||||
@@ -114,13 +118,13 @@ sema_up (struct semaphore *sema)
|
|||||||
|
|
||||||
old_level = intr_disable ();
|
old_level = intr_disable ();
|
||||||
if (!list_empty (&sema->waiters))
|
if (!list_empty (&sema->waiters))
|
||||||
{
|
{
|
||||||
/* Enforces wake-up of the highest priority thread waiting for the
|
/* Enforces wake-up of the highest priority thread waiting for the
|
||||||
semaphore. */
|
semaphore. */
|
||||||
struct list_elem *e = list_min (&sema->waiters, priority_more, NULL);
|
struct list_elem *e = list_max (&sema->waiters, priority_less, NULL);
|
||||||
list_remove (e);
|
list_remove (e);
|
||||||
thread_unblock (list_entry (e, struct thread, elem));
|
thread_unblock (list_entry (e, struct thread, elem));
|
||||||
}
|
}
|
||||||
sema->value++;
|
sema->value++;
|
||||||
intr_set_level (old_level);
|
intr_set_level (old_level);
|
||||||
|
|
||||||
@@ -364,6 +368,19 @@ struct semaphore_elem
|
|||||||
struct semaphore semaphore; /* This semaphore. */
|
struct semaphore semaphore; /* This semaphore. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Function that compares the two threads associated with the provided
|
||||||
|
pointers to their 'elem' member. Returns true if the thread associated
|
||||||
|
with a_ has a lower priority than that of b_. */
|
||||||
|
static bool
|
||||||
|
priority_less (const struct list_elem *a_, const struct list_elem *b_,
|
||||||
|
void *aux UNUSED)
|
||||||
|
{
|
||||||
|
struct thread *a = list_entry (a_, struct thread, elem);
|
||||||
|
struct thread *b = list_entry (b_, struct thread, elem);
|
||||||
|
|
||||||
|
return a->priority < b->priority;
|
||||||
|
}
|
||||||
|
|
||||||
/* Function that compares the two *semaphores* associated with the provided
|
/* Function that compares the two *semaphores* associated with the provided
|
||||||
list_elem structures. [i.e., takes list_elem of semaphore_elem, and]
|
list_elem structures. [i.e., takes list_elem of semaphore_elem, and]
|
||||||
Returns true if the thread associated with the semaphore associated with a_
|
Returns true if the thread associated with the semaphore associated with a_
|
||||||
|
|||||||
@@ -261,7 +261,11 @@ thread_create (const char *name, int priority,
|
|||||||
|
|
||||||
/* Add to run queue. */
|
/* Add to run queue. */
|
||||||
thread_unblock (t);
|
thread_unblock (t);
|
||||||
thread_yield ();
|
|
||||||
|
/* Yield if the newly created thread has higher priority than the current
|
||||||
|
thread. */
|
||||||
|
if (t->priority > thread_current ()->priority)
|
||||||
|
thread_yield ();
|
||||||
|
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user