Clarify nOS-V running task logic

This commit is contained in:
Rodrigo Arias 2022-06-17 17:06:08 +02:00
parent eb060cffb9
commit 553cb45700

View File

@ -331,24 +331,21 @@ pre_task_switch(struct ovni_emu *emu, struct nosv_task *prev_task,
chan_set(&th->chan[CHAN_NOSV_TYPE], next_task->type->gid); chan_set(&th->chan[CHAN_NOSV_TYPE], next_task->type->gid);
} }
static int static struct nosv_task *
is_running_task(struct ovni_emu *emu, struct nosv_task **ptask) get_running_task(struct ovni_emu *emu)
{ {
struct nosv_task *task = emu->cur_thread->task_stack; struct nosv_task *task = emu->cur_thread->task_stack;
if(task && task->state == TASK_ST_RUNNING) if(task && task->state == TASK_ST_RUNNING)
{ return task;
*ptask = task;
return 1;
}
return 0; return NULL;
} }
static void static void
pre_task(struct ovni_emu *emu) pre_task(struct ovni_emu *emu)
{ {
struct nosv_task *prev_task = NULL; struct nosv_task *prev_running = get_running_task(emu);
int was_running_task = is_running_task(emu, &prev_task); int was_running_task = (prev_running != NULL);
/* Update the emulator state, but don't modify the channels yet */ /* Update the emulator state, but don't modify the channels yet */
switch(emu->cur_ev->header.value) switch(emu->cur_ev->header.value)
@ -362,8 +359,8 @@ pre_task(struct ovni_emu *emu)
abort(); abort();
} }
struct nosv_task *next_task = NULL; struct nosv_task *next_running = get_running_task(emu);
int runs_task_now = is_running_task(emu, &next_task); int runs_task_now = (next_running != NULL);
/* Now that we know if the emulator was running a task before /* Now that we know if the emulator was running a task before
* or if it's running one now, update the channels accordingly. */ * or if it's running one now, update the channels accordingly. */
@ -371,21 +368,21 @@ pre_task(struct ovni_emu *emu)
{ {
case 'x': /* Execute: either a nested task or a new one */ case 'x': /* Execute: either a nested task or a new one */
if(was_running_task) if(was_running_task)
pre_task_switch(emu, prev_task, next_task, 1); pre_task_switch(emu, prev_running, next_running, 1);
else else
pre_task_running(emu, next_task); pre_task_running(emu, next_running);
break; break;
case 'e': /* End: either a nested task or the last one */ case 'e': /* End: either a nested task or the last one */
if(runs_task_now) if(runs_task_now)
pre_task_switch(emu, prev_task, next_task, 0); pre_task_switch(emu, prev_running, next_running, 0);
else else
pre_task_not_running(emu, prev_task); pre_task_not_running(emu, prev_running);
break; break;
case 'p': /* Pause */ case 'p': /* Pause */
pre_task_not_running(emu, prev_task); pre_task_not_running(emu, prev_running);
break; break;
case 'r': /* Resume */ case 'r': /* Resume */
pre_task_running(emu, next_task); pre_task_running(emu, next_running);
break; break;
default: default:
break; break;