Add priority comparator function for thread list sorting
This commit is contained in:
@@ -70,6 +70,9 @@ static void *alloc_frame (struct thread *, size_t size);
|
|||||||
static void schedule (void);
|
static void schedule (void);
|
||||||
void thread_schedule_tail (struct thread *prev);
|
void thread_schedule_tail (struct thread *prev);
|
||||||
static tid_t allocate_tid (void);
|
static tid_t allocate_tid (void);
|
||||||
|
static bool priority_more (const struct list_elem *a_,
|
||||||
|
const struct list_elem *b_,
|
||||||
|
void *aux UNUSED)
|
||||||
|
|
||||||
/* Initializes the threading system by transforming the code
|
/* Initializes the threading system by transforming the code
|
||||||
that's currently running into a thread. This can't work in
|
that's currently running into a thread. This can't work in
|
||||||
@@ -350,6 +353,19 @@ thread_foreach (thread_action_func *func, void *aux)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Function that compares the two threads associated with the provided
|
||||||
|
list_elem structures. Returns true if the thread associated with a_ has
|
||||||
|
a higher priority than that of b_. */
|
||||||
|
static bool
|
||||||
|
priority_more (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;
|
||||||
|
}
|
||||||
|
|
||||||
/* Sets the current thread's priority to NEW_PRIORITY. */
|
/* Sets the current thread's priority to NEW_PRIORITY. */
|
||||||
void
|
void
|
||||||
thread_set_priority (int new_priority)
|
thread_set_priority (int new_priority)
|
||||||
|
|||||||
Reference in New Issue
Block a user