From 083dd030180c4ebe1995e1c79a84064f08bb9fc0 Mon Sep 17 00:00:00 2001 From: ligd Date: Wed, 5 Jun 2024 23:48:53 +0800 Subject: [PATCH] sched: change xx_timeout param from pid to tcb Signed-off-by: ligd --- sched/mqueue/mq_timedreceive.c | 17 +++++------------ sched/mqueue/mq_timedsend.c | 16 +++++----------- sched/semaphore/sem_clockwait.c | 2 +- sched/semaphore/sem_tickwait.c | 2 +- sched/semaphore/sem_timeout.c | 14 ++++---------- sched/semaphore/semaphore.h | 2 +- 6 files changed, 17 insertions(+), 36 deletions(-) diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c index 37e2d39eff..c1bbcd2f73 100644 --- a/sched/mqueue/mq_timedreceive.c +++ b/sched/mqueue/mq_timedreceive.c @@ -57,7 +57,7 @@ * becomes non-empty. * * Input Parameters: - * pid - the task ID of the task to wakeup + * arg - the argument provided when the timeout was configured. * * Returned Value: * None @@ -66,9 +66,9 @@ * ****************************************************************************/ -static void nxmq_rcvtimeout(wdparm_t pid) +static void nxmq_rcvtimeout(wdparm_t arg) { - FAR struct tcb_s *wtcb; + FAR struct tcb_s *wtcb = (FAR struct tcb_s *)(uintptr_t)arg; irqstate_t flags; /* Disable interrupts. This is necessary because an interrupt handler may @@ -77,17 +77,11 @@ static void nxmq_rcvtimeout(wdparm_t pid) flags = enter_critical_section(); - /* Get the TCB associated with this pid. It is possible that task may no - * longer be active when this watchdog goes off. - */ - - wtcb = nxsched_get_tcb(pid); - /* It is also possible that an interrupt/context switch beat us to the * punch and already changed the task's state. */ - if (wtcb && wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY) + if (wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY) { /* Restart with task with a timeout error */ @@ -202,8 +196,7 @@ file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg, /* Start the watchdog */ - wd_start(&rtcb->waitdog, ticks, - nxmq_rcvtimeout, nxsched_gettid()); + wd_start(&rtcb->waitdog, ticks, nxmq_rcvtimeout, (wdparm_t)rtcb); } /* Get the message from the message queue */ diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c index c8394ad9a6..84361c6403 100644 --- a/sched/mqueue/mq_timedsend.c +++ b/sched/mqueue/mq_timedsend.c @@ -56,7 +56,7 @@ * becomes non-full. * * Input Parameters: - * pid - the task ID of the task to wakeup + * arg - The argument that was provided when the timeout was configured. * * Returned Value: * None @@ -65,9 +65,9 @@ * ****************************************************************************/ -static void nxmq_sndtimeout(wdparm_t pid) +static void nxmq_sndtimeout(wdparm_t arg) { - FAR struct tcb_s *wtcb; + FAR struct tcb_s *wtcb = (FAR struct tcb_s *)(uintptr_t)arg; irqstate_t flags; /* Disable interrupts. This is necessary because an interrupt handler may @@ -76,17 +76,11 @@ static void nxmq_sndtimeout(wdparm_t pid) flags = enter_critical_section(); - /* Get the TCB associated with this pid. It is possible that task may no - * longer be active when this watchdog goes off. - */ - - wtcb = nxsched_get_tcb(pid); - /* It is also possible that an interrupt/context switch beat us to the * punch and already changed the task's state. */ - if (wtcb != NULL && wtcb->task_state == TSTATE_WAIT_MQNOTFULL) + if (wtcb->task_state == TSTATE_WAIT_MQNOTFULL) { /* Restart with task with a timeout error */ @@ -242,7 +236,7 @@ file_mq_timedsend_internal(FAR struct file *mq, FAR const char *msg, /* Start the watchdog and begin the wait for MQ not full */ - wd_start(&rtcb->waitdog, ticks, nxmq_sndtimeout, nxsched_gettid()); + wd_start(&rtcb->waitdog, ticks, nxmq_sndtimeout, (wdparm_t)rtcb); /* And wait for the message queue to be non-empty */ diff --git a/sched/semaphore/sem_clockwait.c b/sched/semaphore/sem_clockwait.c index 2bfc0479af..745e2e32c2 100644 --- a/sched/semaphore/sem_clockwait.c +++ b/sched/semaphore/sem_clockwait.c @@ -151,7 +151,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, /* Start the watchdog */ - wd_start(&rtcb->waitdog, ticks, nxsem_timeout, nxsched_gettid()); + wd_start(&rtcb->waitdog, ticks, nxsem_timeout, (uintptr_t)rtcb); /* Now perform the blocking wait. If nxsem_wait() fails, the * negated errno value will be returned below. diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index 76d189fd0d..c6d4217395 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -107,7 +107,7 @@ int nxsem_tickwait(FAR sem_t *sem, uint32_t delay) /* Start the watchdog with interrupts still disabled */ - wd_start(&rtcb->waitdog, delay, nxsem_timeout, nxsched_gettid()); + wd_start(&rtcb->waitdog, delay, nxsem_timeout, (uintptr_t)rtcb); /* Now perform the blocking wait */ diff --git a/sched/semaphore/sem_timeout.c b/sched/semaphore/sem_timeout.c index 4bc1700c3c..f5f8a92ae1 100644 --- a/sched/semaphore/sem_timeout.c +++ b/sched/semaphore/sem_timeout.c @@ -47,7 +47,7 @@ * semaphore is acquired. * * Input Parameters: - * pid - The task ID of the task to wakeup + * arg - The argument that was provided when the timeout was configured. * * Returned Value: * None @@ -57,26 +57,20 @@ * ****************************************************************************/ -void nxsem_timeout(wdparm_t pid) +void nxsem_timeout(wdparm_t arg) { - FAR struct tcb_s *wtcb; + FAR struct tcb_s *wtcb = (FAR struct tcb_s *)(uintptr_t)arg; irqstate_t flags; /* Disable interrupts to avoid race conditions */ flags = enter_critical_section(); - /* Get the TCB associated with this PID. It is possible that - * task may no longer be active when this watchdog goes off. - */ - - wtcb = nxsched_get_tcb(pid); - /* It is also possible that an interrupt/context switch beat us to the * punch and already changed the task's state. */ - if (wtcb && wtcb->task_state == TSTATE_WAIT_SEM) + if (wtcb->task_state == TSTATE_WAIT_SEM) { /* Cancel the semaphore wait */ diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index 6c7821819f..b61085ea3c 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -61,7 +61,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode); /* Handle semaphore timer expiration */ -void nxsem_timeout(wdparm_t pid); +void nxsem_timeout(wdparm_t arg); /* Recover semaphore resources with a task or thread is destroyed */