You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/22 08:32:50 UTC

[incubator-nuttx] branch master updated (4c44c6f709 -> 40366f4153)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


    from 4c44c6f709 arch.h: Make _sinit/_einit as an offical interface
     new af72a528f1 sched: merge waitsem and msgwaitq
     new 40366f4153 sched: clear waitsem and msgwaitq after remove blocked

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/nuttx/sched.h             | 10 ++--------
 sched/mqueue/mq_rcvinternal.c     |  7 +++----
 sched/mqueue/mq_recover.c         | 12 ++++++++----
 sched/mqueue/mq_sndinternal.c     |  7 +++----
 sched/mqueue/mq_waitirq.c         |  6 ++----
 sched/sched/sched_removeblocked.c |  4 ++++
 sched/semaphore/sem_post.c        |  6 +-----
 sched/semaphore/sem_recover.c     |  8 ++++----
 sched/semaphore/sem_trywait.c     |  2 +-
 sched/semaphore/sem_wait.c        |  8 ++++----
 sched/semaphore/sem_waitirq.c     |  6 +-----
 11 files changed, 33 insertions(+), 43 deletions(-)


[incubator-nuttx] 02/02: sched: clear waitsem and msgwaitq after remove blocked

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 40366f415397df96e6c66b1178494d0fa6ca75fd
Author: zhangyuan21 <zh...@xiaomi.com>
AuthorDate: Thu Sep 22 10:32:09 2022 +0800

    sched: clear waitsem and msgwaitq after remove blocked
---
 sched/mqueue/mq_rcvinternal.c     | 1 -
 sched/mqueue/mq_sndinternal.c     | 1 -
 sched/mqueue/mq_waitirq.c         | 2 --
 sched/sched/sched_removeblocked.c | 4 ++++
 sched/semaphore/sem_post.c        | 4 ----
 sched/semaphore/sem_waitirq.c     | 4 ----
 6 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c
index 9d5c642c39..c704576af7 100644
--- a/sched/mqueue/mq_rcvinternal.c
+++ b/sched/mqueue/mq_rcvinternal.c
@@ -303,7 +303,6 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
           wd_cancel(&btcb->waitdog);
         }
 
-      btcb->waitobj = NULL;
       msgq->nwaitnotfull--;
       up_unblock_task(btcb);
     }
diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c
index c924ba7df4..af1e3eb44d 100644
--- a/sched/mqueue/mq_sndinternal.c
+++ b/sched/mqueue/mq_sndinternal.c
@@ -410,7 +410,6 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
           wd_cancel(&btcb->waitdog);
         }
 
-      btcb->waitobj = NULL;
       msgq->nwaitnotempty--;
       up_unblock_task(btcb);
     }
diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c
index a9c9767cb6..5ec36c2bac 100644
--- a/sched/mqueue/mq_waitirq.c
+++ b/sched/mqueue/mq_waitirq.c
@@ -83,8 +83,6 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
       msgq = wtcb->waitobj;
       DEBUGASSERT(msgq);
 
-      wtcb->waitobj = NULL;
-
       /* Decrement the count of waiters and cancel the wait */
 
       if (wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY)
diff --git a/sched/sched/sched_removeblocked.c b/sched/sched/sched_removeblocked.c
index 83d184e4fb..b5f479b227 100644
--- a/sched/sched/sched_removeblocked.c
+++ b/sched/sched/sched_removeblocked.c
@@ -67,6 +67,10 @@ void nxsched_remove_blocked(FAR struct tcb_s *btcb)
 
   dq_rem((FAR dq_entry_t *)btcb, TLIST_BLOCKED(task_state));
 
+  /* Indicate that the wait is over. */
+
+  btcb->waitobj = NULL;
+
   /* Make sure the TCB's state corresponds to not being in
    * any list
    */
diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c
index 20f42a4103..917238355a 100644
--- a/sched/semaphore/sem_post.c
+++ b/sched/semaphore/sem_post.c
@@ -155,10 +155,6 @@ int nxsem_post(FAR sem_t *sem)
 
               wd_cancel(&stcb->waitdog);
 
-              /* It is, let the task take the semaphore */
-
-              stcb->waitobj = NULL;
-
               /* Restart the waiting task. */
 
               up_unblock_task(stcb);
diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c
index 89f977afd1..2a296ca166 100644
--- a/sched/semaphore/sem_waitirq.c
+++ b/sched/semaphore/sem_waitirq.c
@@ -97,10 +97,6 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
       sem->semcount++;
 
-      /* Indicate that the semaphore wait is over. */
-
-      wtcb->waitobj = NULL;
-
       /* Mark the errno value for the thread. */
 
       wtcb->errcode = errcode;


[incubator-nuttx] 01/02: sched: merge waitsem and msgwaitq

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit af72a528f1135187bfe79df396cda24a0252f46e
Author: zhangyuan21 <zh...@xiaomi.com>
AuthorDate: Thu Sep 22 10:31:40 2022 +0800

    sched: merge waitsem and msgwaitq
---
 include/nuttx/sched.h         | 10 ++--------
 sched/mqueue/mq_rcvinternal.c |  8 ++++----
 sched/mqueue/mq_recover.c     | 12 ++++++++----
 sched/mqueue/mq_sndinternal.c |  8 ++++----
 sched/mqueue/mq_waitirq.c     |  6 +++---
 sched/semaphore/sem_post.c    |  4 ++--
 sched/semaphore/sem_recover.c |  8 ++++----
 sched/semaphore/sem_trywait.c |  2 +-
 sched/semaphore/sem_wait.c    |  8 ++++----
 sched/semaphore/sem_waitirq.c |  4 ++--
 10 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index e3eaed1658..fbf8e5dced 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -608,9 +608,9 @@ struct tcb_s
   FAR struct dspace_s *dspace;           /* Allocated area for .bss and .data   */
 #endif
 
-  /* POSIX Semaphore Control Fields *****************************************/
+  /* POSIX Semaphore and Message Queue Control Fields ***********************/
 
-  sem_t *waitsem;                        /* Semaphore ID waiting on         */
+  FAR void *waitobj;                     /* Object thread waiting on        */
 
   /* POSIX Signal Control Fields ********************************************/
 
@@ -620,12 +620,6 @@ struct tcb_s
   sq_queue_t sigpostedq;                 /* List of posted signals          */
   siginfo_t  sigunbinfo;                 /* Signal info when task unblocked */
 
-  /* POSIX Named Message Queue Fields ***************************************/
-
-#ifndef CONFIG_DISABLE_MQUEUE
-  FAR struct mqueue_inode_s *msgwaitq;   /* Waiting for this message queue  */
-#endif
-
   /* Robust mutex support ***************************************************/
 
 #if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c
index 3dc6e48c5a..9d5c642c39 100644
--- a/sched/mqueue/mq_rcvinternal.c
+++ b/sched/mqueue/mq_rcvinternal.c
@@ -166,8 +166,8 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
         {
           /* Yes.. Block and try again */
 
-          rtcb           = this_task();
-          rtcb->msgwaitq = msgq;
+          rtcb          = this_task();
+          rtcb->waitobj = msgq;
           msgq->nwaitnotempty++;
 
           /* Initialize the 'errcode" used to communication wake-up error
@@ -286,7 +286,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
        */
 
       for (btcb = (FAR struct tcb_s *)g_waitingformqnotfull.head;
-           btcb && btcb->msgwaitq != msgq;
+           btcb && btcb->waitobj != msgq;
            btcb = btcb->flink)
         {
         }
@@ -303,7 +303,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
           wd_cancel(&btcb->waitdog);
         }
 
-      btcb->msgwaitq = NULL;
+      btcb->waitobj = NULL;
       msgq->nwaitnotfull--;
       up_unblock_task(btcb);
     }
diff --git a/sched/mqueue/mq_recover.c b/sched/mqueue/mq_recover.c
index 2fb1bf3383..ab9c1eabca 100644
--- a/sched/mqueue/mq_recover.c
+++ b/sched/mqueue/mq_recover.c
@@ -56,6 +56,8 @@
 
 void nxmq_recover(FAR struct tcb_s *tcb)
 {
+  FAR struct mqueue_inode_s *msgq;
+
   /* If were were waiting for a timed message queue event, then the
    * timer was canceled and deleted in nxtask_recover() before this
    * function was called.
@@ -63,12 +65,14 @@ void nxmq_recover(FAR struct tcb_s *tcb)
 
   /* Was the task waiting for a message queue to become non-empty? */
 
+  msgq = tcb->waitobj;
+
   if (tcb->task_state == TSTATE_WAIT_MQNOTEMPTY)
     {
       /* Decrement the count of waiters */
 
-      DEBUGASSERT(tcb->msgwaitq && tcb->msgwaitq->nwaitnotempty > 0);
-      tcb->msgwaitq->nwaitnotempty--;
+      DEBUGASSERT(msgq && msgq->nwaitnotempty > 0);
+      msgq->nwaitnotempty--;
     }
 
   /* Was the task waiting for a message queue to become non-full? */
@@ -77,7 +81,7 @@ void nxmq_recover(FAR struct tcb_s *tcb)
     {
       /* Decrement the count of waiters */
 
-      DEBUGASSERT(tcb->msgwaitq && tcb->msgwaitq->nwaitnotfull > 0);
-      tcb->msgwaitq->nwaitnotfull--;
+      DEBUGASSERT(msgq && msgq->nwaitnotfull > 0);
+      msgq->nwaitnotfull--;
     }
 }
diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c
index 5dc27106ea..c924ba7df4 100644
--- a/sched/mqueue/mq_sndinternal.c
+++ b/sched/mqueue/mq_sndinternal.c
@@ -252,8 +252,8 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
        * When we are unblocked, we will try again
        */
 
-      rtcb           = this_task();
-      rtcb->msgwaitq = msgq;
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
       msgq->nwaitnotfull++;
 
       /* Initialize the errcode used to communication wake-up error
@@ -396,7 +396,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
        */
 
       for (btcb = (FAR struct tcb_s *)g_waitingformqnotempty.head;
-           btcb && btcb->msgwaitq != msgq;
+           btcb && btcb->waitobj != msgq;
            btcb = btcb->flink)
         {
         }
@@ -410,7 +410,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
           wd_cancel(&btcb->waitdog);
         }
 
-      btcb->msgwaitq = NULL;
+      btcb->waitobj = NULL;
       msgq->nwaitnotempty--;
       up_unblock_task(btcb);
     }
diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c
index 9f2a014d83..a9c9767cb6 100644
--- a/sched/mqueue/mq_waitirq.c
+++ b/sched/mqueue/mq_waitirq.c
@@ -71,7 +71,7 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
   /* It is possible that an interrupt/context switch beat us to the punch and
    * already changed the task's state.  NOTE:  The operations within the if
-   * are safe because interrupts are always disabled with the msgwaitq,
+   * are safe because interrupts are always disabled with the waitobj,
    * nwaitnotempty, and nwaitnotfull fields are modified.
    */
 
@@ -80,10 +80,10 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
     {
       /* Get the message queue associated with the waiter from the TCB */
 
-      msgq = wtcb->msgwaitq;
+      msgq = wtcb->waitobj;
       DEBUGASSERT(msgq);
 
-      wtcb->msgwaitq = NULL;
+      wtcb->waitobj = NULL;
 
       /* Decrement the count of waiters and cancel the wait */
 
diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c
index 828dffa13f..20f42a4103 100644
--- a/sched/semaphore/sem_post.c
+++ b/sched/semaphore/sem_post.c
@@ -140,7 +140,7 @@ int nxsem_post(FAR sem_t *sem)
            */
 
           for (stcb = (FAR struct tcb_s *)g_waitingforsemaphore.head;
-               (stcb && stcb->waitsem != sem);
+               (stcb && stcb->waitobj != sem);
                stcb = stcb->flink);
 
           if (stcb != NULL)
@@ -157,7 +157,7 @@ int nxsem_post(FAR sem_t *sem)
 
               /* It is, let the task take the semaphore */
 
-              stcb->waitsem = NULL;
+              stcb->waitobj = NULL;
 
               /* Restart the waiting task. */
 
diff --git a/sched/semaphore/sem_recover.c b/sched/semaphore/sem_recover.c
index 40f297bd65..892dc5b3eb 100644
--- a/sched/semaphore/sem_recover.c
+++ b/sched/semaphore/sem_recover.c
@@ -72,17 +72,17 @@ void nxsem_recover(FAR struct tcb_s *tcb)
    * restart the exiting task.
    *
    * NOTE:  In the case that the task is waiting we can assume: (1) That the
-   * task state is TSTATE_WAIT_SEM and (2) that the 'waitsem' in the TCB is
+   * task state is TSTATE_WAIT_SEM and (2) that the 'waitobj' in the TCB is
    * non-null.  If we get here via pthread_cancel() or via task_delete(),
    * then the task state should be preserved; it will be altered in other
-   * cases but in those cases waitsem should be NULL anyway (but we do not
+   * cases but in those cases waitobj should be NULL anyway (but we do not
    * enforce that here).
    */
 
   flags = enter_critical_section();
   if (tcb->task_state == TSTATE_WAIT_SEM)
     {
-      sem_t *sem = tcb->waitsem;
+      FAR sem_t *sem = tcb->waitobj;
       DEBUGASSERT(sem != NULL && sem->semcount < 0);
 
       /* Restore the correct priority of all threads that hold references
@@ -105,7 +105,7 @@ void nxsem_recover(FAR struct tcb_s *tcb)
        * semaphore list.
        */
 
-      tcb->waitsem = NULL;
+      tcb->waitobj = NULL;
     }
 
   /* Release all semphore holders for the task */
diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c
index 4e9cc0ea01..6fe483c51d 100644
--- a/sched/semaphore/sem_trywait.c
+++ b/sched/semaphore/sem_trywait.c
@@ -91,7 +91,7 @@ int nxsem_trywait(FAR sem_t *sem)
 
           sem->semcount--;
           nxsem_add_holder(sem);
-          rtcb->waitsem = NULL;
+          rtcb->waitobj = NULL;
           ret = OK;
         }
       else
diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c
index 29580d72cc..67d6af70f4 100644
--- a/sched/semaphore/sem_wait.c
+++ b/sched/semaphore/sem_wait.c
@@ -98,7 +98,7 @@ int nxsem_wait(FAR sem_t *sem)
 
           sem->semcount--;
           nxsem_add_holder(sem);
-          rtcb->waitsem = NULL;
+          rtcb->waitobj = NULL;
           ret = OK;
         }
 
@@ -112,7 +112,7 @@ int nxsem_wait(FAR sem_t *sem)
            * semaphore
            */
 
-          DEBUGASSERT(rtcb->waitsem == NULL);
+          DEBUGASSERT(rtcb->waitobj == NULL);
 
           /* Handle the POSIX semaphore (but don't set the owner yet) */
 
@@ -120,7 +120,7 @@ int nxsem_wait(FAR sem_t *sem)
 
           /* Save the waited on semaphore in the TCB */
 
-          rtcb->waitsem = sem;
+          rtcb->waitobj = sem;
 
           /* If priority inheritance is enabled, then check the priority of
            * the holder of the semaphore.
@@ -166,7 +166,7 @@ int nxsem_wait(FAR sem_t *sem)
            * - nxsem_canceled() was called to restore the priority of all
            *   threads that hold a reference to the semaphore,
            * - The semaphore count was decremented, and
-           * - tcb->waitsem was nullifed.
+           * - tcb->waitobj was nullifed.
            *
            * It is necessary to do these things in sem_waitirq.c because a
            * long time may elapse between the time that the signal was issued
diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c
index 08170b55cc..89f977afd1 100644
--- a/sched/semaphore/sem_waitirq.c
+++ b/sched/semaphore/sem_waitirq.c
@@ -80,7 +80,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
   if (wtcb->task_state == TSTATE_WAIT_SEM)
     {
-      sem_t *sem = wtcb->waitsem;
+      FAR sem_t *sem = wtcb->waitobj;
       DEBUGASSERT(sem != NULL && sem->semcount < 0);
 
       /* Restore the correct priority of all threads that hold references
@@ -99,7 +99,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
       /* Indicate that the semaphore wait is over. */
 
-      wtcb->waitsem = NULL;
+      wtcb->waitobj = NULL;
 
       /* Mark the errno value for the thread. */