修复内核资源释放的不完整的bug
This commit is contained in:
@@ -85,10 +85,20 @@ void arch_set_enable_irq_prio(int inx, int sub_prio, int pre_prio);
|
||||
{ \
|
||||
write_sysreg(0, PRIMASK); \
|
||||
} while (0)
|
||||
|
||||
static inline void preemption(void)
|
||||
{
|
||||
cli();
|
||||
sti();
|
||||
}
|
||||
|
||||
static inline umword_t intr_status(void)
|
||||
{
|
||||
return read_sysreg(PRIMASK);
|
||||
}
|
||||
|
||||
void sys_startup(void);
|
||||
|
||||
|
||||
// systick.c
|
||||
umword_t sys_tick_cnt_get(void);
|
||||
|
||||
@@ -27,6 +27,7 @@ enum thread_state
|
||||
THREAD_DEAD,
|
||||
THREAD_SUSPEND, //!< 只有接收和发送ipc消息时才能挂起
|
||||
THREAD_READY,
|
||||
THREAD_TODEAD, //!< 该标志标志线程马上要死亡了,应该立刻停止操作
|
||||
};
|
||||
typedef struct
|
||||
{
|
||||
@@ -115,4 +116,6 @@ void thread_unbind(thread_t *th);
|
||||
void thread_send_wait(thread_t *th);
|
||||
void thread_sched(void);
|
||||
void thread_suspend(thread_t *th);
|
||||
void thread_dead(thread_t *th);
|
||||
void thread_todead(thread_t *th, bool_t is_sche);
|
||||
void thread_ready(thread_t *th, bool_t is_sche);
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @file ipc.c
|
||||
* @author zhangzheng (1358745329@qq.com)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-29
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "ipc.h"
|
||||
#include "types.h"
|
||||
@@ -106,9 +106,21 @@ static void timeout_times_wake_ipc(ipc_t *ipc)
|
||||
slist_foreach(item, &ipc->wait_send, node) //!< 第二次循环等待irq里面的等待者
|
||||
{
|
||||
//!< 超时时间满后直接唤醒等待者
|
||||
thread_ready(item->th, TRUE);
|
||||
if (thread_get_status(item->th) == THREAD_SUSPEND)
|
||||
{
|
||||
thread_todead(item->th, TRUE);
|
||||
}
|
||||
}
|
||||
slist_foreach(item, &ipc->recv_send, node) //!< 第二次循环等待irq里面的等待者
|
||||
{
|
||||
//!< 超时时间满后直接唤醒等待者
|
||||
if (thread_get_status(item->th) == THREAD_SUSPEND)
|
||||
{
|
||||
thread_todead(item->th, TRUE);
|
||||
}
|
||||
}
|
||||
thread_sched();
|
||||
preemption();
|
||||
}
|
||||
/**
|
||||
* @brief ipc_wait_item_t结构体初始化
|
||||
@@ -137,6 +149,7 @@ static void ipc_wait_item_init(ipc_wait_item_t *item, ipc_t *ipc, thread_t *th,
|
||||
*/
|
||||
static int add_wait_unlock(ipc_t *ipc, slist_head_t *head, thread_t *th, umword_t times, spinlock_t *lock, int status)
|
||||
{
|
||||
int ret = 0;
|
||||
ipc_wait_item_t item;
|
||||
|
||||
ipc_wait_item_init(&item, ipc, th, times);
|
||||
@@ -159,10 +172,14 @@ static int add_wait_unlock(ipc_t *ipc, slist_head_t *head, thread_t *th, umword_
|
||||
}
|
||||
if (item.sleep_times == 0)
|
||||
{
|
||||
return -ETIMEDOUT;
|
||||
ret = -ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
if (thread_get_status(th) == THREAD_TODEAD)
|
||||
{
|
||||
ret = -ESHUTDOWN;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief 拿出等待队列中的第一个并唤醒
|
||||
@@ -242,10 +259,11 @@ __check:
|
||||
status = spinlock_lock(&ipc->lock);
|
||||
if (ipc->svr_th->status != THREAD_SUSPEND)
|
||||
{
|
||||
if (add_wait_unlock(ipc, &ipc->wait_send, th,
|
||||
timeout.send_timeout, &ipc->lock, status) < 0)
|
||||
ret = add_wait_unlock(ipc, &ipc->wait_send, th,
|
||||
timeout.send_timeout, &ipc->lock, status);
|
||||
if (ret < 0)
|
||||
{
|
||||
return msg_tag_init4(MSG_TAG_KNL_ERR, 0, 0, -EWTIMEDOUT);
|
||||
return msg_tag_init4(MSG_TAG_KNL_ERR, 0, 0, ret);
|
||||
}
|
||||
goto __check;
|
||||
}
|
||||
@@ -441,7 +459,6 @@ static void ipc_release_stage1(kobject_t *kobj)
|
||||
{
|
||||
ref_counter_dec_and_release(&ipc->svr_th->ref, &ipc->svr_th->kobj);
|
||||
}
|
||||
|
||||
}
|
||||
static void ipc_release_stage2(kobject_t *kobj)
|
||||
{
|
||||
|
||||
@@ -174,7 +174,7 @@ static void irq_sender_stage2(kobject_t *kobj)
|
||||
task_t *cur_task = thread_get_current_task();
|
||||
|
||||
mm_limit_free(cur_task->lim, th);
|
||||
printk("irq_sender 0x%x\n", kobj);
|
||||
printk("irq_sender release 0x%x\n", kobj);
|
||||
}
|
||||
/**
|
||||
* @brief 初始化
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @file task.c
|
||||
* @author zhangzheng (1358745329@qq.com)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-29
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "task.h"
|
||||
@@ -167,7 +167,7 @@ static void task_release_stage2(kobject_t *kobj)
|
||||
|
||||
mm_limit_free_align(tk->lim, tk->mm_space.mm_block, tk->mm_space.mm_block_size);
|
||||
mm_limit_free(tk->lim, tk);
|
||||
if (cur_tk == tk)
|
||||
// if (cur_tk == tk)
|
||||
{
|
||||
thread_sched();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @file thread.c
|
||||
* @author zhangzheng (1358745329@qq.com)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-09-29
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
@@ -57,17 +57,16 @@ static void thread_release_stage1(kobject_t *kobj)
|
||||
thread_t *th = container_of(kobj, thread_t, kobj);
|
||||
kobject_invalidate(kobj);
|
||||
thread_unbind(th);
|
||||
if (th->status == THREAD_READY)
|
||||
if (th->status == THREAD_READY || th->status == THREAD_TODEAD)
|
||||
{
|
||||
thread_suspend(th);
|
||||
thread_dead(th);
|
||||
}
|
||||
}
|
||||
static void thread_release_stage2(kobject_t *kobj)
|
||||
{
|
||||
thread_t *th = container_of(kobj, thread_t, kobj);
|
||||
thread_t *cur_th = thread_get_current();
|
||||
|
||||
printk("thread 0x%x\n", kobj);
|
||||
printk("release thread 0x%x\n", kobj);
|
||||
mm_limit_free_align(th->lim, kobj, THREAD_BLOCK_SIZE);
|
||||
|
||||
if (cur_th == th)
|
||||
@@ -130,6 +129,21 @@ void thread_suspend(thread_t *th)
|
||||
th->status = THREAD_SUSPEND;
|
||||
thread_sched();
|
||||
}
|
||||
/**
|
||||
* @brief 线程死亡
|
||||
*
|
||||
* @param th
|
||||
*/
|
||||
void thread_dead(thread_t *th)
|
||||
{
|
||||
if (!slist_in_list(&th->sche.node))
|
||||
{
|
||||
assert(slist_in_list(&th->sche.node));
|
||||
}
|
||||
scheduler_del(&th->sche);
|
||||
th->status = THREAD_DEAD;
|
||||
thread_sched();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 进行一次调度
|
||||
@@ -166,6 +180,20 @@ void thread_ready(thread_t *th, bool_t is_sche)
|
||||
thread_sched();
|
||||
}
|
||||
}
|
||||
void thread_todead(thread_t *th, bool_t is_sche)
|
||||
{
|
||||
if (!!slist_in_list(&th->sche.node))
|
||||
{
|
||||
assert(!slist_in_list(&th->sche.node));
|
||||
}
|
||||
scheduler_add(&th->sche);
|
||||
th->status = THREAD_TODEAD;
|
||||
if (is_sche)
|
||||
{
|
||||
thread_sched();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 创建线程
|
||||
*
|
||||
@@ -182,6 +210,7 @@ thread_t *thread_create(ram_limit_t *ram)
|
||||
}
|
||||
memset(th, 0, THREAD_BLOCK_SIZE);
|
||||
thread_init(th, ram);
|
||||
printk("create thread 0x%x\n", th);
|
||||
return th;
|
||||
}
|
||||
enum thread_op
|
||||
@@ -284,7 +313,6 @@ static kobject_t *thread_create_func(ram_limit_t *lim, umword_t arg0, umword_t a
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
printk("thread 0x%x\n", kobj);
|
||||
return kobj;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ int main(int argc, char *args[])
|
||||
ns_test();
|
||||
#endif
|
||||
irq_test();
|
||||
fs_test();
|
||||
// fs_test();
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS));
|
||||
ulog_write_str(u_get_global_env()->log_hd, "Error.\n");
|
||||
return 0;
|
||||
|
||||
@@ -47,11 +47,11 @@ int main(int argc, char *args[])
|
||||
// printf("app load fail, 0x%x\n", ret);
|
||||
// }
|
||||
|
||||
// ret = app_load("app", &env);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// printf("app load fail, 0x%x\n", ret);
|
||||
// }
|
||||
ret = app_load("app", &env);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("app load fail, 0x%x\n", ret);
|
||||
}
|
||||
// namespace_init(ipc_hd);
|
||||
|
||||
// namespace_loop();
|
||||
|
||||
Reference in New Issue
Block a user