From 7b7335bc5d7459d8c798808278a19f6346d44b4f Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 9 Feb 2021 16:36:40 +0900 Subject: [PATCH] Fix GNU/Linux emulation. Signed-off-by: NIIBE Yutaka --- ChangeLog | 5 +++++ chopstx-gnu-linux.c | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index be85ed8..5c10760 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-02-09 NIIBE Yutaka + + * chopstx-gnu-linux.c (voluntary_context_switch): Fix for the case + when chx_idle suggests no context switch (tp_prev == tp_next). + 2021-02-08 NIIBE Yutaka * chopstx.c (chx_recv_irq): Bug fix when no waiter. diff --git a/chopstx-gnu-linux.c b/chopstx-gnu-linux.c index 0fb24a2..d562030 100644 --- a/chopstx-gnu-linux.c +++ b/chopstx-gnu-linux.c @@ -2,7 +2,7 @@ * chopstx-gnu-linux.c - Threads and only threads: Arch specific code * for GNU/Linux emulation * - * Copyright (C) 2017, 2018, 2019 Flying Stone Technology + * Copyright (C) 2017, 2018, 2019, 2021 Flying Stone Technology * Author: NIIBE Yutaka * * This file is a part of Chopstx, a thread library for embedded. @@ -260,14 +260,23 @@ preempted_context_switch (struct chx_thread *tp_next) static uintptr_t voluntary_context_switch (struct chx_thread *tp_next) { - struct chx_thread *tp, *tp_prev; - - if (!tp_next) - tp_next = chx_idle (); + struct chx_thread *tp; + struct chx_thread *tp_prev; tp_prev = chx_running (); - chx_set_running (tp_next); - swapcontext (&tp_prev->tc, &tp_next->tc); + if (!tp_next) + { + chx_set_running (NULL); + tp_next = chx_idle (); + chx_set_running (tp_next); + if (tp_prev != tp_next) + swapcontext (&tp_prev->tc, &tp_next->tc); + } + else + { + chx_set_running (tp_next); + swapcontext (&tp_prev->tc, &tp_next->tc); + } chx_cpu_sched_unlock (); tp = chx_running ();