From 96c3debe6a7488ad84e87a0ec2a7189edf4fbd81 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 17 Oct 2022 15:49:16 +0800 Subject: [PATCH] sched/mqueue: decoupling condition member to common prologue Signed-off-by: chao an --- include/nuttx/mqueue.h | 19 +++++++++++++------ sched/init/nx_start.c | 4 ++-- sched/mqueue/mq_msgqalloc.c | 4 ++-- sched/mqueue/mq_rcvinternal.c | 8 ++++---- sched/mqueue/mq_recover.c | 8 ++++---- sched/mqueue/mq_sndinternal.c | 8 ++++---- sched/mqueue/mq_waitirq.c | 8 ++++---- 7 files changed, 33 insertions(+), 26 deletions(-) diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 191b193a7e..0b4f6cb19a 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -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 diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index 3d329194a6..5adc075b07 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -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 diff --git a/sched/mqueue/mq_msgqalloc.c b/sched/mqueue/mq_msgqalloc.c index 0728278b74..68376996f3 100644 --- a/sched/mqueue/mq_msgqalloc.c +++ b/sched/mqueue/mq_msgqalloc.c @@ -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 { diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index 328c21bf87..0081dcb1be 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -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); } diff --git a/sched/mqueue/mq_recover.c b/sched/mqueue/mq_recover.c index ab9c1eabca..cb8d7e57d1 100644 --- a/sched/mqueue/mq_recover.c +++ b/sched/mqueue/mq_recover.c @@ -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--; } } diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index 5ec5d2ba80..f570cbfea7 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -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); } diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c index 5ec36c2bac..c43d874fa3 100644 --- a/sched/mqueue/mq_waitirq.c +++ b/sched/mqueue/mq_waitirq.c @@ -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. */