From 1dde0f42d417eac2ca608a6e79f3478ad3fb9498 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Sun, 11 Apr 2021 19:08:47 +0200 Subject: [PATCH] core/sched: keep scheduler clist internal to sched adds sched_runq_advance(prio) used it in core/thread and test malloc_thread_safety --- core/include/sched.h | 20 ++++++++++++++++++++ core/thread.c | 2 +- tests/malloc_thread_safety/main.c | 8 +------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/core/include/sched.h b/core/include/sched.h index ceea4771ba..d62a555b92 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -278,6 +278,26 @@ typedef void (*sched_callback_t)(kernel_pid_t active, kernel_pid_t next); void sched_register_cb(sched_callback_t callback); #endif /* MODULE_SCHED_CB */ +/** + * @brief Advance a runqueue + * + * Advances the runqueue of that priority by one step to the next thread in + * that priority. + * Next time that priority is scheduled the now first thread will get activated. + * Calling this will not start the scheduler. + * + * @warning This API is not intended for out of tree users. + * Breaking API changes will be done without notice and + * without deprecation. Consider yourself warned! + * + * @param prio The priority of the runqueue to advance + * + */ +static inline void sched_runq_advance(uint8_t prio) +{ + clist_lpoprpush(&sched_runqueues[prio]); +} + #ifdef __cplusplus } #endif diff --git a/core/thread.c b/core/thread.c index 8e318c2f82..4c56608ca3 100644 --- a/core/thread.c +++ b/core/thread.c @@ -143,7 +143,7 @@ void thread_yield(void) thread_t *me = thread_get_active(); if (me->status >= STATUS_ON_RUNQUEUE) { - clist_lpoprpush(&sched_runqueues[me->priority]); + sched_runq_advance(me->priority); } irq_restore(old_state); diff --git a/tests/malloc_thread_safety/main.c b/tests/malloc_thread_safety/main.c index 1570fb1f33..b6a4fbe652 100644 --- a/tests/malloc_thread_safety/main.c +++ b/tests/malloc_thread_safety/main.c @@ -81,12 +81,6 @@ void * t1_t2_realloc_func(void *arg) return NULL; } -static void evil_schedule_hack_dont_do_this_at_home(uint8_t prio) -{ - extern clist_node_t sched_runqueues[SCHED_PRIO_LEVELS]; - clist_lpoprpush(&sched_runqueues[prio]); -} - int main(void) { kernel_pid_t t1, t2; @@ -128,7 +122,7 @@ int main(void) /* shuffle t1 and t2 in their run queue. This should eventually hit * during a call to malloc() or free() and disclose any missing * guards */ - evil_schedule_hack_dont_do_this_at_home(THREAD_PRIORITY_MAIN + 1); + sched_runq_advance(THREAD_PRIORITY_MAIN + 1); } /* Don't keep threads spinning */