minor bug fix in sys_kill

This commit is contained in:
TXuian 2025-01-07 22:15:15 +08:00
parent fd95d9a7de
commit 42b17738ee
5 changed files with 9 additions and 10 deletions

View File

@ -118,7 +118,7 @@ struct TaskLifecycleOperations {
/* new a task control block, checkout #sys_spawn for usage */ /* new a task control block, checkout #sys_spawn for usage */
struct Thread* (*new_thread)(struct MemSpace* pmemspace); struct Thread* (*new_thread)(struct MemSpace* pmemspace);
/* free a task control block, this calls #free_user_pgdir to free all vitual spaces */ /* 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 { struct XiziTaskManager {

View File

@ -40,10 +40,9 @@ int sys_exit(struct Thread* ptask)
{ {
assert(ptask != NULL); assert(ptask != NULL);
ptask->dead = true; ptask->dead = true;
// free that task straightly if it's a blocked task // awake the task if it's a blocked task
if (ptask->snode.state == BLOCKED) { if (ptask->snode.state == BLOCKED || ptask->snode.state == SLEEPING) {
struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag); THREAD_TRANS_STATE(ptask, TRANS_WAKING);
tlo->free_pcb(ptask);
} }
// yield current task in case it wants to exit itself // yield current task in case it wants to exit itself
THREAD_TRANS_STATE(cur_cpu()->task, READY); THREAD_TRANS_STATE(cur_cpu()->task, READY);

View File

@ -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); struct ThreadStackPointer loaded_sp = load_user_stack(pmemspace, argv);
if (loaded_sp.stack_idx == -1) { if (loaded_sp.stack_idx == -1) {
ERROR("Uable to load params to memspace.\n"); 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); struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag);
tlo->free_pcb(task); tlo->free_thread(task);
return -1; return -1;
} }

View File

@ -53,7 +53,7 @@ bool find_runable_task(RbtNode* node, void* data)
return true; return true;
} else { } else {
struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag); struct TaskLifecycleOperations* tlo = GetSysObject(struct TaskLifecycleOperations, &xizi_task_manager.task_lifecycle_ops_tag);
tlo->free_pcb(thd); tlo->free_thread(thd);
return false; 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) 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)); assert(enqueue(&thd->snode.state_trans_signal_queue, state, NULL));
int res = rbt_insert(&g_scheduler.state_trans_ref_map, thd->tid, (void*)thd); int res = rbt_insert(&g_scheduler.state_trans_ref_map, thd->tid, (void*)thd);
assert(RBTTREE_INSERT_SECC == res || RBTTREE_INSERT_EXISTED == res); assert(RBTTREE_INSERT_SECC == res || RBTTREE_INSERT_EXISTED == res);

View File

@ -281,7 +281,7 @@ static struct Thread* _new_thread(struct MemSpace* pmemspace)
struct TaskLifecycleOperations task_lifecycle_ops = { struct TaskLifecycleOperations task_lifecycle_ops = {
.new_thread = _new_thread, .new_thread = _new_thread,
.free_pcb = _free_thread, .free_thread = _free_thread,
}; };
static void task_state_set_running(struct Thread* task) static void task_state_set_running(struct Thread* task)