Add extra checks when running a new task in nosv

This commit is contained in:
Rodrigo Arias 2021-12-09 15:56:04 +01:00
parent de70a057d4
commit f8d989b214

View File

@ -90,6 +90,7 @@ pre_task_create(struct ovni_emu *emu)
task->id = emu->cur_ev->payload.i32[0]; task->id = emu->cur_ev->payload.i32[0];
task->type_id = emu->cur_ev->payload.i32[1]; task->type_id = emu->cur_ev->payload.i32[1];
task->state = TASK_ST_CREATED; task->state = TASK_ST_CREATED;
task->thread = NULL;
/* Ensure the task id is new */ /* Ensure the task id is new */
HASH_FIND_INT(emu->cur_proc->tasks, &task->id, p); HASH_FIND_INT(emu->cur_proc->tasks, &task->id, p);
@ -121,6 +122,12 @@ pre_task_execute(struct ovni_emu *emu)
if(task == NULL) if(task == NULL)
die("cannot find task with id %d\n", taskid); die("cannot find task with id %d\n", taskid);
if(task->state != TASK_ST_CREATED)
die("task state is not created\n");
if(task->thread != NULL)
die("task already has a thread assigned\n");
if(emu->cur_thread->state != TH_ST_RUNNING) if(emu->cur_thread->state != TH_ST_RUNNING)
die("thread state is not running\n"); die("thread state is not running\n");