mirror of
https://github.com/apache/nuttx.git
synced 2026-09-27 10:46:02 +08:00
nuttx/sched: remove nxsched_remove_blocked from up_unblock_task
It takes about 10 cycles to obtain the task list according to the task status. In most cases, we know the task status, so we can directly delete the task from the specified task list to reduce time consuming.
This commit is contained in:
committed by
Masayuki Ishikawa
parent
ae46cd4fa1
commit
e54b602208
@@ -279,13 +279,15 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
||||
|
||||
if (msgq->cmn.nwaitnotfull > 0)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Find the highest priority task that is waiting for
|
||||
* this queue to be not-full in waitfornotfull list.
|
||||
* This must be performed in a critical section because
|
||||
* messages can be sent from interrupt handlers.
|
||||
*/
|
||||
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNFLIST(msgq->cmn));
|
||||
btcb = (FAR struct tcb_s *)dq_remfirst(MQ_WNFLIST(msgq->cmn));
|
||||
|
||||
/* If one was found, unblock it. NOTE: There is a race
|
||||
* condition here: the queue might be full again by the
|
||||
@@ -300,7 +302,19 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
||||
}
|
||||
|
||||
msgq->cmn.nwaitnotfull--;
|
||||
up_unblock_task(btcb);
|
||||
|
||||
/* Indicate that the wait is over. */
|
||||
|
||||
btcb->waitobj = NULL;
|
||||
|
||||
/* Add the task to ready-to-run task list and
|
||||
* perform the context switch if one is needed
|
||||
*/
|
||||
|
||||
if (nxsched_add_readytorun(btcb))
|
||||
{
|
||||
up_unblock_task(btcb, rtcb);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the length of the message transferred to the user buffer */
|
||||
|
||||
@@ -388,6 +388,8 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
||||
|
||||
if (msgq->cmn.nwaitnotempty > 0)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Find the highest priority task that is waiting for
|
||||
* this queue to be non-empty in waitfornotempty
|
||||
* list. leave_critical_section() should give us sufficient
|
||||
@@ -395,7 +397,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
||||
* in this list
|
||||
*/
|
||||
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNELIST(msgq->cmn));
|
||||
btcb = (FAR struct tcb_s *)dq_remfirst(MQ_WNELIST(msgq->cmn));
|
||||
|
||||
/* If one was found, unblock it */
|
||||
|
||||
@@ -407,7 +409,19 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
||||
}
|
||||
|
||||
msgq->cmn.nwaitnotempty--;
|
||||
up_unblock_task(btcb);
|
||||
|
||||
/* Indicate that the wait is over. */
|
||||
|
||||
btcb->waitobj = NULL;
|
||||
|
||||
/* Add the task to ready-to-run task list and
|
||||
* perform the context switch if one is needed
|
||||
*/
|
||||
|
||||
if (nxsched_add_readytorun(btcb))
|
||||
{
|
||||
up_unblock_task(btcb, rtcb);
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <nuttx/mqueue.h>
|
||||
|
||||
#include "mqueue/mqueue.h"
|
||||
#include "sched/sched.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@@ -61,6 +62,7 @@
|
||||
|
||||
void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct mqueue_inode_s *msgq;
|
||||
|
||||
/* It is possible that an interrupt/context switch beat us to the punch and
|
||||
@@ -80,18 +82,29 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
||||
{
|
||||
DEBUGASSERT(msgq->cmn.nwaitnotempty > 0);
|
||||
msgq->cmn.nwaitnotempty--;
|
||||
dq_rem((FAR dq_entry_t *)wtcb, MQ_WNELIST(msgq->cmn));
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUGASSERT(msgq->cmn.nwaitnotfull > 0);
|
||||
msgq->cmn.nwaitnotfull--;
|
||||
dq_rem((FAR dq_entry_t *)wtcb, MQ_WNFLIST(msgq->cmn));
|
||||
}
|
||||
|
||||
/* Indicate that the wait is over. */
|
||||
|
||||
wtcb->waitobj = NULL;
|
||||
|
||||
/* Mark the error value for the thread. */
|
||||
|
||||
wtcb->errcode = errcode;
|
||||
|
||||
/* Restart the task. */
|
||||
/* Add the task to ready-to-run task list and
|
||||
* perform the context switch if one is needed
|
||||
*/
|
||||
|
||||
up_unblock_task(wtcb);
|
||||
if (nxsched_add_readytorun(wtcb))
|
||||
{
|
||||
up_unblock_task(wtcb, rtcb);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -221,13 +221,15 @@ ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, long msgtyp,
|
||||
|
||||
if (msgq->cmn.nwaitnotfull > 0)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Find the highest priority task that is waiting for
|
||||
* this queue to be not-full in g_waitingformqnotfull list.
|
||||
* This must be performed in a critical section because
|
||||
* messages can be sent from interrupt handlers.
|
||||
*/
|
||||
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNFLIST(msgq->cmn));
|
||||
btcb = (FAR struct tcb_s *)dq_remfirst(MQ_WNFLIST(msgq->cmn));
|
||||
|
||||
/* If one was found, unblock it. NOTE: There is a race
|
||||
* condition here: the queue might be full again by the
|
||||
@@ -242,7 +244,19 @@ ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, long msgtyp,
|
||||
}
|
||||
|
||||
msgq->cmn.nwaitnotfull--;
|
||||
up_unblock_task(btcb);
|
||||
|
||||
/* Indicate that the wait is over. */
|
||||
|
||||
btcb->waitobj = NULL;
|
||||
|
||||
/* Add the task to ready-to-run task list and
|
||||
* perform the context switch if one is needed
|
||||
*/
|
||||
|
||||
if (nxsched_add_readytorun(btcb))
|
||||
{
|
||||
up_unblock_task(btcb, rtcb);
|
||||
}
|
||||
}
|
||||
|
||||
errout_with_critical:
|
||||
|
||||
+16
-2
@@ -216,6 +216,8 @@ int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg)
|
||||
|
||||
if (msgq->cmn.nwaitnotempty > 0)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Find the highest priority task that is waiting for
|
||||
* this queue to be non-empty in g_waitingformqnotempty
|
||||
* list. enter_critical_section() should give us sufficient
|
||||
@@ -223,7 +225,7 @@ int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg)
|
||||
* in this list
|
||||
*/
|
||||
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNELIST(msgq->cmn));
|
||||
btcb = (FAR struct tcb_s *)dq_remfirst(MQ_WNELIST(msgq->cmn));
|
||||
|
||||
/* If one was found, unblock it */
|
||||
|
||||
@@ -235,7 +237,19 @@ int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg)
|
||||
}
|
||||
|
||||
msgq->cmn.nwaitnotempty--;
|
||||
up_unblock_task(btcb);
|
||||
|
||||
/* Indicate that the wait is over. */
|
||||
|
||||
btcb->waitobj = NULL;
|
||||
|
||||
/* Add the task to ready-to-run task list and
|
||||
* perform the context switch if one is needed
|
||||
*/
|
||||
|
||||
if (nxsched_add_readytorun(btcb))
|
||||
{
|
||||
up_unblock_task(btcb, rtcb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user