mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
sched: mqueue wait list optimize
This commit is contained in:
@@ -85,6 +85,9 @@
|
|||||||
# define nxmq_pollnotify(msgq, eventset)
|
# define nxmq_pollnotify(msgq, eventset)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
# define MQ_WNELIST(mq) (&((mq)->waitfornotempty))
|
||||||
|
# define MQ_WNFLIST(mq) (&((mq)->waitfornotfull))
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Type Declarations
|
* Public Type Declarations
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -94,6 +97,8 @@
|
|||||||
struct mqueue_inode_s
|
struct mqueue_inode_s
|
||||||
{
|
{
|
||||||
FAR struct inode *inode; /* Containing inode */
|
FAR struct inode *inode; /* Containing inode */
|
||||||
|
dq_queue_t waitfornotempty; /* Task list waiting for not empty */
|
||||||
|
dq_queue_t waitfornotfull; /* Task list waiting for not full */
|
||||||
struct list_node msglist; /* Prioritized message list */
|
struct list_node msglist; /* Prioritized message list */
|
||||||
int16_t maxmsgs; /* Maximum number of messages in the queue */
|
int16_t maxmsgs; /* Maximum number of messages in the queue */
|
||||||
int16_t nmsgs; /* Number of message in the queue */
|
int16_t nmsgs; /* Number of message in the queue */
|
||||||
|
|||||||
+4
-20
@@ -138,22 +138,6 @@ dq_queue_t g_pendingtasks;
|
|||||||
|
|
||||||
dq_queue_t g_waitingforsignal;
|
dq_queue_t g_waitingforsignal;
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_MQUEUE
|
|
||||||
/* This is the list of all tasks that are blocked waiting for a message
|
|
||||||
* queue to become non-empty.
|
|
||||||
*/
|
|
||||||
|
|
||||||
dq_queue_t g_waitingformqnotempty;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_MQUEUE
|
|
||||||
/* This is the list of all tasks that are blocked waiting for a message
|
|
||||||
* queue to become non-full.
|
|
||||||
*/
|
|
||||||
|
|
||||||
dq_queue_t g_waitingformqnotfull;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_PAGING
|
#ifdef CONFIG_PAGING
|
||||||
/* This is the list of all tasks that are blocking waiting for a page fill */
|
/* This is the list of all tasks that are blocking waiting for a page fill */
|
||||||
|
|
||||||
@@ -243,12 +227,12 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] =
|
|||||||
#ifndef CONFIG_DISABLE_MQUEUE
|
#ifndef CONFIG_DISABLE_MQUEUE
|
||||||
,
|
,
|
||||||
{ /* TSTATE_WAIT_MQNOTEMPTY */
|
{ /* TSTATE_WAIT_MQNOTEMPTY */
|
||||||
&g_waitingformqnotempty,
|
(FAR void *)offsetof(struct mqueue_inode_s, waitfornotempty),
|
||||||
TLIST_ATTR_PRIORITIZED
|
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_OFFSET
|
||||||
},
|
},
|
||||||
{ /* TSTATE_WAIT_MQNOTFULL */
|
{ /* TSTATE_WAIT_MQNOTFULL */
|
||||||
&g_waitingformqnotfull,
|
(FAR void *)offsetof(struct mqueue_inode_s, waitfornotfull),
|
||||||
TLIST_ATTR_PRIORITIZED
|
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_OFFSET
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_PAGING
|
#ifdef CONFIG_PAGING
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ int nxmq_alloc_msgq(FAR struct mq_attr *attr,
|
|||||||
#ifndef CONFIG_DISABLE_MQUEUE_NOTIFICATION
|
#ifndef CONFIG_DISABLE_MQUEUE_NOTIFICATION
|
||||||
msgq->ntpid = INVALID_PROCESS_ID;
|
msgq->ntpid = INVALID_PROCESS_ID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
dq_init(&msgq->waitfornotempty);
|
||||||
|
dq_init(&msgq->waitfornotfull);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -280,16 +280,12 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
|||||||
if (msgq->nwaitnotfull > 0)
|
if (msgq->nwaitnotfull > 0)
|
||||||
{
|
{
|
||||||
/* Find the highest priority task that is waiting for
|
/* Find the highest priority task that is waiting for
|
||||||
* this queue to be not-full in g_waitingformqnotfull list.
|
* this queue to be not-full in waitfornotfull list.
|
||||||
* This must be performed in a critical section because
|
* This must be performed in a critical section because
|
||||||
* messages can be sent from interrupt handlers.
|
* messages can be sent from interrupt handlers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (btcb = (FAR struct tcb_s *)g_waitingformqnotfull.head;
|
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNFLIST(msgq));
|
||||||
btcb && btcb->waitobj != msgq;
|
|
||||||
btcb = btcb->flink)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If one was found, unblock it. NOTE: There is a race
|
/* If one was found, unblock it. NOTE: There is a race
|
||||||
* condition here: the queue might be full again by the
|
* condition here: the queue might be full again by the
|
||||||
|
|||||||
@@ -389,17 +389,13 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
|||||||
if (msgq->nwaitnotempty > 0)
|
if (msgq->nwaitnotempty > 0)
|
||||||
{
|
{
|
||||||
/* Find the highest priority task that is waiting for
|
/* Find the highest priority task that is waiting for
|
||||||
* this queue to be non-empty in g_waitingformqnotempty
|
* this queue to be non-empty in waitfornotempty
|
||||||
* list. leave_critical_section() should give us sufficient
|
* list. leave_critical_section() should give us sufficient
|
||||||
* protection since interrupts should never cause a change
|
* protection since interrupts should never cause a change
|
||||||
* in this list
|
* in this list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (btcb = (FAR struct tcb_s *)g_waitingformqnotempty.head;
|
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNELIST(msgq));
|
||||||
btcb && btcb->waitobj != msgq;
|
|
||||||
btcb = btcb->flink)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If one was found, unblock it */
|
/* If one was found, unblock it */
|
||||||
|
|
||||||
|
|||||||
@@ -178,22 +178,6 @@ extern dq_queue_t g_pendingtasks;
|
|||||||
|
|
||||||
extern dq_queue_t g_waitingforsignal;
|
extern dq_queue_t g_waitingforsignal;
|
||||||
|
|
||||||
/* This is the list of all tasks that are blocked waiting for a message
|
|
||||||
* queue to become non-empty.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_MQUEUE
|
|
||||||
extern dq_queue_t g_waitingformqnotempty;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This is the list of all tasks that are blocked waiting for a message
|
|
||||||
* queue to become non-full.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_MQUEUE
|
|
||||||
extern dq_queue_t g_waitingformqnotfull;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This is the list of all tasks that are blocking waiting for a page fill */
|
/* This is the list of all tasks that are blocking waiting for a page fill */
|
||||||
|
|
||||||
#ifdef CONFIG_PAGING
|
#ifdef CONFIG_PAGING
|
||||||
|
|||||||
Reference in New Issue
Block a user