sched: enforce ref-counting on current task/thread pointers

This commit is contained in:
2026-04-01 18:17:05 +01:00
parent 15c2207ab9
commit 512356ac2d
28 changed files with 364 additions and 103 deletions
+12 -4
View File
@@ -37,7 +37,7 @@ struct port *port_cast(struct object *obj)
static void wait_for_reply(struct msg *msg, unsigned long *lock_flags)
{
struct wait_item waiter;
struct thread *self = current_thread();
struct thread *self = get_current_thread();
wait_item_init(&waiter, self);
for (;;) {
@@ -52,6 +52,7 @@ static void wait_for_reply(struct msg *msg, unsigned long *lock_flags)
}
self->tr_state = THREAD_READY;
put_current_thread(self);
}
struct port *port_create(void)
@@ -83,9 +84,12 @@ kern_status_t port_connect(struct port *port, struct channel *remote)
msg->msg_status = KMSG_ASYNC;
msg->msg_type = KERN_MSG_TYPE_EVENT;
msg->msg_event = KERN_MSG_EVENT_CONNECTION;
msg->msg_sender_thread_id = current_thread()->tr_id;
msg->msg_sender_port_id = port->p_base.ob_id;
struct thread *self = get_current_thread();
msg->msg_sender_thread_id = self->tr_id;
put_current_thread(self);
unsigned long flags;
channel_lock_irqsave(remote, &flags);
channel_enqueue_msg(remote, msg);
@@ -112,9 +116,12 @@ kern_status_t port_disconnect(struct port *port)
msg->msg_status = KMSG_ASYNC;
msg->msg_type = KERN_MSG_TYPE_EVENT;
msg->msg_event = KERN_MSG_EVENT_DISCONNECTION;
msg->msg_sender_thread_id = current_thread()->tr_id;
msg->msg_sender_port_id = port->p_base.ob_id;
struct thread *self = get_current_thread();
msg->msg_sender_thread_id = self->tr_id;
put_current_thread(self);
unsigned long flags;
channel_lock_irqsave(port->p_remote, &flags);
channel_enqueue_msg(port->p_remote, msg);
@@ -136,7 +143,7 @@ kern_status_t port_send_msg(
return KERN_BAD_STATE;
}
struct thread *self = current_thread();
struct thread *self = get_current_thread();
struct msg msg;
memset(&msg, 0x0, sizeof msg);
msg.msg_type = KERN_MSG_TYPE_DATA;
@@ -156,6 +163,7 @@ kern_status_t port_send_msg(
channel_lock_irqsave(port->p_remote, &flags);
btree_delete(&port->p_remote->c_msg, &msg.msg_node);
channel_unlock_irqrestore(port->p_remote, flags);
put_current_thread(self);
return msg.msg_result;
}