Add function to compare the priority of two semaphores
This commit is contained in:
@@ -265,6 +265,27 @@ struct semaphore_elem
|
||||
struct semaphore semaphore; /* This semaphore. */
|
||||
};
|
||||
|
||||
/* Function that compares the two *semaphores* associated with the provided
|
||||
list_elem structures. [i.e., takes list_elem of semaphore_elem, and]
|
||||
Returns true if the thread associated with the semaphore associated with a_
|
||||
has a higher priority than that of b_. */
|
||||
static bool
|
||||
sema_priority_more(const struct list_elem *a_, const struct list_elem *b_,
|
||||
void *aux UNUSED)
|
||||
{
|
||||
struct semaphore_elem *a = list_entry(a_, struct semaphore_elem, elem);
|
||||
struct semaphore_elem *b = list_entry(b_, struct semaphore_elem, elem);
|
||||
|
||||
/* Get the highest priority thread from the waiters list of each semaphore. By
|
||||
design, this is the first element in the list (See sema_down). */
|
||||
struct thread *a_thread =
|
||||
list_entry(list_front(&a->semaphore.waiters), struct thread, elem);
|
||||
struct thread *b_thread =
|
||||
list_entry(list_front(&b->semaphore.waiters), struct thread, elem);
|
||||
|
||||
return a_thread->priority > b_thread->priority;
|
||||
}
|
||||
|
||||
/* Initializes condition variable COND. A condition variable
|
||||
allows one piece of code to signal a condition and cooperating
|
||||
code to receive the signal and act upon it. */
|
||||
|
||||
Reference in New Issue
Block a user