diff --git a/kernel/tasks.c b/kernel/tasks.c index 8465b245..39e215e1 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -1268,12 +1268,6 @@ void scheduler(void) if (curr_task->status == TASK_FINISHED) curr_task->status = TASK_INVALID; - /* if the task is using the FPU, we need to save the FPU context */ - if (curr_task->flags & TASK_FPU_USED) { - save_fpu_state(&(curr_task->fpu)); - curr_task->flags &= ~TASK_FPU_USED; - } - spinlock_irqsave_lock(&runqueues[core_id].lock); // check timers @@ -1358,6 +1352,12 @@ get_task_out: spinlock_irqsave_unlock(&runqueues[core_id].lock); if (curr_task != orig_task) { + /* if the original task is using the FPU, we need to save the FPU context */ + if ((orig_task->flags & TASK_FPU_USED) && (orig_task->status == TASK_READY)) { + save_fpu_state(&(orig_task->fpu)); + orig_task->flags &= ~TASK_FPU_USED; + } + //kprintf("schedule from %u to %u with prio %u on core %u\n", // orig_task->id, curr_task->id, (uint32_t)curr_task->prio, CORE_ID); switch_task(curr_task->id);