diff --git a/Ubiquitous/XiZi_AIoT/softkernel/include/task.h b/Ubiquitous/XiZi_AIoT/softkernel/include/task.h index 267c66388..948ca3128 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/include/task.h +++ b/Ubiquitous/XiZi_AIoT/softkernel/include/task.h @@ -118,7 +118,7 @@ struct TaskLifecycleOperations { /* new a task control block, checkout #sys_spawn for usage */ struct Thread* (*new_thread)(struct MemSpace* pmemspace); /* free a task control block, this calls #free_user_pgdir to free all vitual spaces */ - void (*free_pcb)(struct Thread*); + void (*free_thread)(struct Thread*); }; struct XiziTaskManager { diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_exit.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_exit.c index e02be1f6b..8c3aab27c 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_exit.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_exit.c @@ -40,10 +40,9 @@ int sys_exit(struct Thread* ptask) { assert(ptask != NULL); ptask->dead = true; - // free that task straightly if it's a blocked task - if (ptask->snode.state == BLOCKED) { - struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag); - tlo->free_pcb(ptask); + // awake the task if it's a blocked task + if (ptask->snode.state == BLOCKED || ptask->snode.state == SLEEPING) { + THREAD_TRANS_STATE(ptask, TRANS_WAKING); } // yield current task in case it wants to exit itself THREAD_TRANS_STATE(cur_cpu()->task, READY); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c index 25a372c0c..1057e7b4b 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c @@ -40,9 +40,9 @@ int sys_new_thread(struct MemSpace* pmemspace, struct Thread* task, uintptr_t en struct ThreadStackPointer loaded_sp = load_user_stack(pmemspace, argv); if (loaded_sp.stack_idx == -1) { ERROR("Uable to load params to memspace.\n"); - /* memspace is freed alone with free_pcb() */ + /* memspace is freed alone with free_thread() */ struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag); - tlo->free_pcb(task); + tlo->free_thread(task); return -1; } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c b/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c index 987124f07..9907c3ce2 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c @@ -53,7 +53,7 @@ bool find_runable_task(RbtNode* node, void* data) return true; } else { struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag); - tlo->free_pcb(thd); + tlo->free_thread(thd); return false; } @@ -93,7 +93,7 @@ bool init_schedule_node(struct ScheduleNode* snode, struct Thread* bind_thd) void enqueue_task_trans_state(struct Thread* thd, enum ThreadState state) { - /// @todo handle memory drain + /// @todo (current bug) handle memory drain assert(enqueue(&thd->snode.state_trans_signal_queue, state, NULL)); int res = rbt_insert(&g_scheduler.state_trans_ref_map, thd->tid, (void*)thd); assert(RBTTREE_INSERT_SECC == res || RBTTREE_INSERT_EXISTED == res); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/task.c b/Ubiquitous/XiZi_AIoT/softkernel/task/task.c index 5205ae24f..929787d92 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/task.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/task.c @@ -281,7 +281,7 @@ static struct Thread* _new_thread(struct MemSpace* pmemspace) struct TaskLifecycleOperations task_lifecycle_ops = { .new_thread = _new_thread, - .free_pcb = _free_thread, + .free_thread = _free_thread, }; static void task_state_set_running(struct Thread* task)