On Thu, Sep 9, 2021 at 12:01 AM Katsuhiro Suzuki
On 2021/09/08 16:22, Yasushi SHOJI wrote:The reason why we set _current to the new thread is that we can't set it afterOn Wed, Sep 8, 2021 at 10:23 AM Katsuhiro Suzuki <katsuhiro@...> wrote:Because to keep consistency for another context switching (by preemption) and
we switch to the new thread. The newly switched thread will just start
the point it left off. Otherwise, we have to make sure that each and
every arch must
set _current to the new thread in `arch_switch()`.
At an IRQ, you know the `_current` is the currently executing thread and you can
get a new thread from ready_q, if needed.
At explicit switch, you are given both old and new threads.
So in both cases, we _can_ implement the switch.
I agree that we need to do similar things for arch_switch and irq, and
love to use
exact same code for both, but it might be better to have separate code for
each situation. Or, at least use .macro to construct parts of it.
ps. Unfortunately, unlike the Linux kernel, we don't have any way to
get the thread struct
from a stack pointer, IIRC.
just my 2 cents,