From c097d769b1aa9caaa9fa7a36669d8609d4295cdb Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 5 May 2022 15:11:07 +0200 Subject: [PATCH] Transform asserts and follow coding style --- CMakeLists.txt | 2 +- emu_nosv.c | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4324342..64a4c25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ set(CMAKE_C_EXTENSIONS FALSE) option(ENABLE_DEBUG_LOG "Enable debug messages (very verbose)") if(ENABLE_DEBUG_LOG) - add_definitions(-DENABLE_DEBUG) + add_definitions(-DENABLE_DEBUG) endif() if(NOT CMAKE_BUILD_TYPE) diff --git a/emu_nosv.c b/emu_nosv.c index 2313477..8d5ef8e 100644 --- a/emu_nosv.c +++ b/emu_nosv.c @@ -283,25 +283,29 @@ pre_task_running(struct ovni_emu *emu, struct nosv_task *task) } static void -pre_task_switch(struct ovni_emu *emu, struct nosv_task *prev_task, struct nosv_task *next_task) +pre_task_switch(struct ovni_emu *emu, struct nosv_task *prev_task, + struct nosv_task *next_task) { struct ovni_ethread *th; - struct ovni_eproc *proc; - - assert(prev_task); - assert(next_task); - assert(prev_task != next_task); th = emu->cur_thread; - proc = emu->cur_proc; - assert(next_task->id > 0); - assert(next_task->type_id > 0); - assert(proc->appid > 0); + if(!prev_task || !next_task) + die("cannot switch to or from a NULL task\n"); + + if(prev_task == next_task) + die("cannot switch to the same task\n"); + + if(next_task->id <= 0) + die("next task id must be positive\n"); + + if(next_task->type_id <= 0) + die("next task type id must be positive\n"); chan_set(&th->chan[CHAN_NOSV_TASKID], next_task->id); - if (prev_task->type_id != next_task->type_id) + /* Only emit the new type if necessary */ + if(prev_task->type_id != next_task->type_id) chan_set(&th->chan[CHAN_NOSV_TYPEID], next_task->type_id); } @@ -310,7 +314,6 @@ pre_task(struct ovni_emu *emu) { struct nosv_task *prev_task, *next_task; - assert(emu->cur_thread); prev_task = emu->cur_thread->running_task; switch(emu->cur_ev->header.value) @@ -326,11 +329,12 @@ pre_task(struct ovni_emu *emu) next_task = emu->cur_thread->running_task; - // Unless we're creating a task, register the switch - if (emu->cur_ev->header.value != 'c') { - if(!next_task) + /* Unless we're creating a task, register the switch */ + if(emu->cur_ev->header.value != 'c') + { + if(next_task == NULL) pre_task_not_running(emu); - else if(!prev_task) + else if(prev_task == NULL) pre_task_running(emu, next_task); else pre_task_switch(emu, prev_task, next_task);