Add comparison function for thread list elements based on thread priority

This commit is contained in:
Themis Demetriades
2024-10-15 11:50:04 +01:00
parent 4ed64cf173
commit 1821d73b09
2 changed files with 14 additions and 0 deletions

View File

@@ -599,6 +599,17 @@ allocate_tid (void)
return tid; 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'. /* Offset of `stack' member within `struct thread'.
Used by switch.S, which can't figure it out on its own. */ Used by switch.S, which can't figure it out on its own. */
uint32_t thread_stack_ofs = offsetof (struct thread, stack); uint32_t thread_stack_ofs = offsetof (struct thread, stack);

View File

@@ -139,4 +139,7 @@ void thread_set_nice (int);
int thread_get_recent_cpu (void); int thread_get_recent_cpu (void);
int thread_get_load_avg (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 */ #endif /* threads/thread.h */