修复在真实硬件上内核资源释放不完全的bug.

This commit is contained in:
zhangzheng
2023-09-29 23:49:17 +08:00
parent 322634889b
commit 4ba8d8fb9a
4 changed files with 49 additions and 10 deletions

View File

@@ -50,6 +50,9 @@ typedef struct msg_tag
.msg_buf_len = (msg_words), \
.map_buf_len = (buf_words), \
.prot = (p)})
#define msg_tag_get_prot(tag) \
((int16_t)((tag).prot))
#define msg_tag_get_val(tag) msg_tag_get_prot(tag)
typedef union syscall_prot
{

View File

@@ -23,11 +23,11 @@ typedef struct thread thread_t;
enum thread_state
{
THREAD_IDLE,
THREAD_DEAD,
THREAD_IDLE, //!< 空闲状态
THREAD_DEAD, //!< 死亡状态
THREAD_SUSPEND, //!< 只有接收和发送ipc消息时才能挂起
THREAD_READY,
THREAD_TODEAD, //!< 该标志标志线程马上要死亡了,应该立刻停止操作
THREAD_READY, //!< 正常工作状态
THREAD_TODEAD, //!< 该标志标志线程马上要死亡了,执行完必要操作后进入THREAD_DEAD状态
};
typedef struct
{

View File

@@ -278,11 +278,12 @@ __check:
ipc->svr_th->msg.tag = tag;
thread_ready(ipc->svr_th, TRUE); //!< 直接唤醒接受者
ipc->last_cli_th = th; //!< 设置上一次发送的客户端
if (add_wait_unlock(ipc, &ipc->recv_send, th, timeout.recv_timeout, &ipc->lock, status) < 0)
ret = add_wait_unlock(ipc, &ipc->recv_send, th, timeout.recv_timeout, &ipc->lock, status);
if (ret < 0)
{
// ref_counter_dec_and_release(&ipc->last_cli_th->ref, &ipc->last_cli_th->kobj);
ipc->last_cli_th = NULL;
ref_counter_dec_and_release(&ipc->last_cli_th->ref, &ipc->last_cli_th->kobj);
return msg_tag_init4(MSG_TAG_KNL_ERR, 0, 0, -ERTIMEDOUT);
return msg_tag_init4(MSG_TAG_KNL_ERR, 0, 0, ret);
}
// spinlock_set(&ipc->lock, status);
tmp_tag = th->msg.tag;
@@ -376,6 +377,10 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag,
ref_counter_inc(&th->ref); //!< 引用计数+1
tag = ipc_call(ipc, th, f, in_tag, ipc_timeout_create(f->r[1])); //!< ipc call
ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1
if (msg_tag_get_val(tag) == -ESHUTDOWN)
{
thread_dead(th);
}
}
}
break;
@@ -390,6 +395,10 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag,
ref_counter_inc(&th->ref); //!< 引用计数+1
tag = ipc_wait(ipc, th, f, in_tag); //!< 进入等待
ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1
if (msg_tag_get_val(tag) == -ESHUTDOWN)
{
thread_dead(th);
}
f->r[1] = ipc->user_id;
}
}
@@ -405,6 +414,10 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag,
ref_counter_inc(&th->ref); //!< 引用计数+1
int ret = ipc_reply(ipc, th, f, in_tag);
ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1
if (msg_tag_get_val(tag) == -ESHUTDOWN)
{
thread_dead(th);
}
tag = msg_tag_init4(0, 0, 0, ret);
}
}
@@ -437,6 +450,7 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag,
{
if (ipc->svr_th == th)
{
ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1
ipc->svr_th = NULL;
tag = msg_tag_init4(0, 0, 0, 0);
}

View File

@@ -55,12 +55,34 @@ static bool_t thread_put(kobject_t *kobj)
static void thread_release_stage1(kobject_t *kobj)
{
thread_t *th = container_of(kobj, thread_t, kobj);
thread_t *cur = thread_get_current();
kobject_invalidate(kobj);
thread_unbind(th);
if (th->status == THREAD_READY || th->status == THREAD_TODEAD)
if (cur == th)
{
thread_dead(th);
if (th->status == THREAD_READY || th->status == THREAD_TODEAD)
{
thread_dead(th);
}
}
else
{
if (th->status == THREAD_TODEAD) //!< 如果在TODEAD状态则等待其死亡
{
while (th->status != THREAD_DEAD)
{
//!< 循环等待其死亡
thread_sched();
preemption();
}
}
else if (th->status == THREAD_READY)
{
thread_dead(th);
}
}
thread_unbind(th);
}
static void thread_release_stage2(kobject_t *kobj)
{