sched/mqueue: decoupling condition member to common prologue
Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
parent
39a2acb821
commit
96c3debe6a
@ -85,25 +85,32 @@
|
||||
# define nxmq_pollnotify(msgq, eventset)
|
||||
#endif
|
||||
|
||||
# define MQ_WNELIST(mq) (&((mq)->waitfornotempty))
|
||||
# define MQ_WNFLIST(mq) (&((mq)->waitfornotfull))
|
||||
# define MQ_WNELIST(cmn) (&((cmn).waitfornotempty))
|
||||
# define MQ_WNFLIST(cmn) (&((cmn).waitfornotfull))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/* Common prologue of all message queue structures. */
|
||||
|
||||
struct mqueue_cmn_s
|
||||
{
|
||||
dq_queue_t waitfornotempty; /* Task list waiting for not empty */
|
||||
dq_queue_t waitfornotfull; /* Task list waiting for not full */
|
||||
int16_t nwaitnotfull; /* Number tasks waiting for not full */
|
||||
int16_t nwaitnotempty; /* Number tasks waiting for not empty */
|
||||
};
|
||||
|
||||
/* This structure defines a message queue */
|
||||
|
||||
struct mqueue_inode_s
|
||||
{
|
||||
struct mqueue_cmn_s cmn; /* Common prologue */
|
||||
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 */
|
||||
int16_t maxmsgs; /* Maximum number of messages in the queue */
|
||||
int16_t nmsgs; /* Number of message in the queue */
|
||||
int16_t nwaitnotfull; /* Number tasks waiting for not full */
|
||||
int16_t nwaitnotempty; /* Number tasks waiting for not empty */
|
||||
#if CONFIG_MQ_MAXMSGSIZE < 256
|
||||
uint8_t maxmsgsize; /* Max size of message in message queue */
|
||||
#else
|
||||
|
@ -227,11 +227,11 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] =
|
||||
#ifndef CONFIG_DISABLE_MQUEUE
|
||||
,
|
||||
{ /* TSTATE_WAIT_MQNOTEMPTY */
|
||||
(FAR void *)offsetof(struct mqueue_inode_s, waitfornotempty),
|
||||
(FAR void *)offsetof(struct mqueue_inode_s, cmn.waitfornotempty),
|
||||
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_OFFSET
|
||||
},
|
||||
{ /* TSTATE_WAIT_MQNOTFULL */
|
||||
(FAR void *)offsetof(struct mqueue_inode_s, waitfornotfull),
|
||||
(FAR void *)offsetof(struct mqueue_inode_s, cmn.waitfornotfull),
|
||||
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_OFFSET
|
||||
}
|
||||
#endif
|
||||
|
@ -102,8 +102,8 @@ int nxmq_alloc_msgq(FAR struct mq_attr *attr,
|
||||
msgq->ntpid = INVALID_PROCESS_ID;
|
||||
#endif
|
||||
|
||||
dq_init(&msgq->waitfornotempty);
|
||||
dq_init(&msgq->waitfornotfull);
|
||||
dq_init(&msgq->cmn.waitfornotempty);
|
||||
dq_init(&msgq->cmn.waitfornotfull);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
|
||||
|
||||
rtcb = this_task();
|
||||
rtcb->waitobj = msgq;
|
||||
msgq->nwaitnotempty++;
|
||||
msgq->cmn.nwaitnotempty++;
|
||||
|
||||
/* Initialize the 'errcode" used to communication wake-up error
|
||||
* conditions.
|
||||
@ -277,7 +277,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
||||
|
||||
/* Check if any tasks are waiting for the MQ not full event. */
|
||||
|
||||
if (msgq->nwaitnotfull > 0)
|
||||
if (msgq->cmn.nwaitnotfull > 0)
|
||||
{
|
||||
/* Find the highest priority task that is waiting for
|
||||
* this queue to be not-full in waitfornotfull list.
|
||||
@ -285,7 +285,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
||||
* messages can be sent from interrupt handlers.
|
||||
*/
|
||||
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNFLIST(msgq));
|
||||
btcb = (FAR struct tcb_s *)dq_peek(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
|
||||
@ -299,7 +299,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
||||
wd_cancel(&btcb->waitdog);
|
||||
}
|
||||
|
||||
msgq->nwaitnotfull--;
|
||||
msgq->cmn.nwaitnotfull--;
|
||||
up_unblock_task(btcb);
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ void nxmq_recover(FAR struct tcb_s *tcb)
|
||||
{
|
||||
/* Decrement the count of waiters */
|
||||
|
||||
DEBUGASSERT(msgq && msgq->nwaitnotempty > 0);
|
||||
msgq->nwaitnotempty--;
|
||||
DEBUGASSERT(msgq && msgq->cmn.nwaitnotempty > 0);
|
||||
msgq->cmn.nwaitnotempty--;
|
||||
}
|
||||
|
||||
/* Was the task waiting for a message queue to become non-full? */
|
||||
@ -81,7 +81,7 @@ void nxmq_recover(FAR struct tcb_s *tcb)
|
||||
{
|
||||
/* Decrement the count of waiters */
|
||||
|
||||
DEBUGASSERT(msgq && msgq->nwaitnotfull > 0);
|
||||
msgq->nwaitnotfull--;
|
||||
DEBUGASSERT(msgq && msgq->cmn.nwaitnotfull > 0);
|
||||
msgq->cmn.nwaitnotfull--;
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
|
||||
|
||||
rtcb = this_task();
|
||||
rtcb->waitobj = msgq;
|
||||
msgq->nwaitnotfull++;
|
||||
msgq->cmn.nwaitnotfull++;
|
||||
|
||||
/* Initialize the errcode used to communication wake-up error
|
||||
* conditions.
|
||||
@ -386,7 +386,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
||||
|
||||
/* Check if any tasks are waiting for the MQ not empty event. */
|
||||
|
||||
if (msgq->nwaitnotempty > 0)
|
||||
if (msgq->cmn.nwaitnotempty > 0)
|
||||
{
|
||||
/* Find the highest priority task that is waiting for
|
||||
* this queue to be non-empty in waitfornotempty
|
||||
@ -395,7 +395,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
||||
* in this list
|
||||
*/
|
||||
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNELIST(msgq));
|
||||
btcb = (FAR struct tcb_s *)dq_peek(MQ_WNELIST(msgq->cmn));
|
||||
|
||||
/* If one was found, unblock it */
|
||||
|
||||
@ -406,7 +406,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
||||
wd_cancel(&btcb->waitdog);
|
||||
}
|
||||
|
||||
msgq->nwaitnotempty--;
|
||||
msgq->cmn.nwaitnotempty--;
|
||||
up_unblock_task(btcb);
|
||||
}
|
||||
|
||||
|
@ -87,13 +87,13 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
||||
|
||||
if (wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY)
|
||||
{
|
||||
DEBUGASSERT(msgq->nwaitnotempty > 0);
|
||||
msgq->nwaitnotempty--;
|
||||
DEBUGASSERT(msgq->cmn.nwaitnotempty > 0);
|
||||
msgq->cmn.nwaitnotempty--;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUGASSERT(msgq->nwaitnotfull > 0);
|
||||
msgq->nwaitnotfull--;
|
||||
DEBUGASSERT(msgq->cmn.nwaitnotfull > 0);
|
||||
msgq->cmn.nwaitnotfull--;
|
||||
}
|
||||
|
||||
/* Mark the error value for the thread. */
|
||||
|
Loading…
Reference in New Issue
Block a user