From 1821d73b09616e61e5d8344db49ad42b7492723d Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Tue, 15 Oct 2024 11:50:04 +0100 Subject: [PATCH] Add comparison function for thread list elements based on thread priority --- src/threads/thread.c | 11 +++++++++++ src/threads/thread.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/threads/thread.c b/src/threads/thread.c index ed305ad..8e18ca9 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -599,6 +599,17 @@ allocate_tid (void) return tid; } +/* Returns true iff the priority of the first list element's thread is greater + than that of the second list element's thread. */ +bool +thread_priority_greater (const struct list_elem *a, const struct list_elem *b, + void *aux) +{ + struct thread *ta = list_entry (a, struct thread, elem); + struct thread *tb = list_entry (b, struct thread, elem); + return ta->priority > tb->priority; +} + /* Offset of `stack' member within `struct thread'. Used by switch.S, which can't figure it out on its own. */ uint32_t thread_stack_ofs = offsetof (struct thread, stack); diff --git a/src/threads/thread.h b/src/threads/thread.h index f36d7ac..0503af9 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -139,4 +139,7 @@ void thread_set_nice (int); int thread_get_recent_cpu (void); int thread_get_load_avg (void); +/* Returns true iff the priority of the first list element's thread is greater + than that of the second list element's thread. */ +list_less_func thread_priority_greater; #endif /* threads/thread.h */