From 2e361e129f68122f7be7f335c439a348f82a1169 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 26 Aug 2016 07:01:25 +0200 Subject: [PATCH] revise get_next_core to return always a valid core --- hermit/kernel/tasks.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/hermit/kernel/tasks.c b/hermit/kernel/tasks.c index c58c6aab8..535795d12 100644 --- a/hermit/kernel/tasks.c +++ b/hermit/kernel/tasks.c @@ -45,6 +45,7 @@ */ extern const void tls_start; extern const void tls_end; +extern atomic_int32_t cpu_online; #define TLS_OFFSET 8 @@ -317,14 +318,18 @@ uint32_t get_next_core_id(void) if (core_id >= MAX_CORES) core_id = CORE_ID; - // we assume OpenMP applications // => number of threads is (normaly) equal to the number of cores // => search next available core - for(i=0, core_id=(core_id+1)%MAX_CORES; i= MAX_CORES) || !readyqueues[core_id].idle) - core_id = CORE_ID; + if (BUILTIN_EXPECT(core_id >= MAX_CORES, 0)) + { + spinlock_irqsave_unlock(&table_lock); + ret = -EINVAL; + goto out; + } for(i=0; i