You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/11/04 07:51:09 UTC

[incubator-nuttx] branch master updated: sched: remove sched_continue, merge code

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d4ba93067e sched: remove sched_continue, merge code
d4ba93067e is described below

commit d4ba93067ee76e656c39d42e6dcf5f8daa48322e
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Oct 21 00:14:37 2022 +0800

    sched: remove sched_continue, merge code
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 sched/group/group_continue.c  |  3 +-
 sched/mqueue/mq_waitirq.c     | 52 +++++++++++++---------------------
 sched/sched/Make.defs         |  2 +-
 sched/sched/sched.h           |  1 -
 sched/sched/sched_continue.c  | 66 -------------------------------------------
 sched/semaphore/sem_waitirq.c | 49 ++++++++++++--------------------
 sched/signal/sig_dispatch.c   |  6 +++-
 7 files changed, 45 insertions(+), 134 deletions(-)

diff --git a/sched/group/group_continue.c b/sched/group/group_continue.c
index 41c17087e4..9a03b0d623 100644
--- a/sched/group/group_continue.c
+++ b/sched/group/group_continue.c
@@ -64,7 +64,7 @@ static int group_continue_handler(pid_t pid, FAR void *arg)
   rtcb = nxsched_get_tcb(pid);
   if (rtcb != NULL)
     {
-      nxsched_continue(rtcb);
+      up_unblock_task(rtcb);
     }
 
   /* Always return zero.  We need to visit each member of the group */
@@ -82,6 +82,7 @@ static int group_continue_handler(pid_t pid, FAR void *arg)
  * Description:
  *   Resume all members of the task group.  This is SIGCONT default signal
  *   action logic.
+ *   Note: this function should used within critical_section
  *
  * Input Parameters:
  *   tcb - TCB of the task to be retained.
diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c
index c43d874fa3..aa2e800c5f 100644
--- a/sched/mqueue/mq_waitirq.c
+++ b/sched/mqueue/mq_waitirq.c
@@ -46,6 +46,7 @@
  *   task that is waiting on a message queue -- either for a queue to
  *   becoming not full (on mq_send and friends) or not empty (on mq_receive
  *   and friends).
+ *   Note: this function should used within critical_section
  *
  * Input Parameters:
  *   wtcb - A pointer to the TCB of the task that is waiting on a message
@@ -61,13 +62,6 @@
 void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 {
   FAR struct mqueue_inode_s *msgq;
-  irqstate_t flags;
-
-  /* Disable interrupts.  This is necessary because an interrupt handler may
-   * attempt to send a message while we are doing this.
-   */
-
-  flags = enter_critical_section();
 
   /* 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
@@ -75,37 +69,29 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
    * nwaitnotempty, and nwaitnotfull fields are modified.
    */
 
-  if (wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY ||
-      wtcb->task_state == TSTATE_WAIT_MQNOTFULL)
-    {
-      /* Get the message queue associated with the waiter from the TCB */
-
-      msgq = wtcb->waitobj;
-      DEBUGASSERT(msgq);
-
-      /* Decrement the count of waiters and cancel the wait */
+  /* Get the message queue associated with the waiter from the TCB */
 
-      if (wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY)
-        {
-          DEBUGASSERT(msgq->cmn.nwaitnotempty > 0);
-          msgq->cmn.nwaitnotempty--;
-        }
-      else
-        {
-          DEBUGASSERT(msgq->cmn.nwaitnotfull > 0);
-          msgq->cmn.nwaitnotfull--;
-        }
+  msgq = wtcb->waitobj;
+  DEBUGASSERT(msgq);
 
-      /* Mark the error value for the thread. */
+  /* Decrement the count of waiters and cancel the wait */
 
-      wtcb->errcode = errcode;
+  if (wtcb->task_state == TSTATE_WAIT_MQNOTEMPTY)
+    {
+      DEBUGASSERT(msgq->cmn.nwaitnotempty > 0);
+      msgq->cmn.nwaitnotempty--;
+    }
+  else
+    {
+      DEBUGASSERT(msgq->cmn.nwaitnotfull > 0);
+      msgq->cmn.nwaitnotfull--;
+    }
 
-      /* Restart the task. */
+  /* Mark the error value for the thread. */
 
-      up_unblock_task(wtcb);
-    }
+  wtcb->errcode = errcode;
 
-  /* Interrupts may now be enabled. */
+  /* Restart the task. */
 
-  leave_critical_section(flags);
+  up_unblock_task(wtcb);
 }
diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs
index 326887b060..e2084557a0 100644
--- a/sched/sched/Make.defs
+++ b/sched/sched/Make.defs
@@ -41,7 +41,7 @@ CSRCS += sched_getaffinity.c sched_setaffinity.c
 endif
 
 ifeq ($(CONFIG_SIG_SIGSTOP_ACTION),y)
-CSRCS += sched_suspend.c sched_continue.c
+CSRCS += sched_suspend.c
 endif
 
 ifeq ($(CONFIG_SCHED_WAITPID),y)
diff --git a/sched/sched/sched.h b/sched/sched/sched.h
index 26cb851114..9dbc3ab2cb 100644
--- a/sched/sched/sched.h
+++ b/sched/sched/sched.h
@@ -357,7 +357,6 @@ void nxsched_sporadic_lowpriority(FAR struct tcb_s *tcb);
 
 #ifdef CONFIG_SIG_SIGSTOP_ACTION
 void nxsched_suspend(FAR struct tcb_s *tcb);
-void nxsched_continue(FAR struct tcb_s *tcb);
 #endif
 
 #ifdef CONFIG_SMP
diff --git a/sched/sched/sched_continue.c b/sched/sched/sched_continue.c
deleted file mode 100644
index c89d08b121..0000000000
--- a/sched/sched/sched_continue.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
- * sched/sched/sched_continue.c
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.  The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <sched.h>
-#include <assert.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/sched.h>
-#include <nuttx/arch.h>
-
-#include "sched/sched.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxsched_continue
- *
- * Description:
- *   Resume the specified thread.  This is normally calling indirectly
- *   via group_continue();
- *
- ****************************************************************************/
-
-void nxsched_continue(FAR struct tcb_s *tcb)
-{
-  irqstate_t flags;
-
-  DEBUGASSERT(tcb != NULL && tcb->task_state == TSTATE_TASK_STOPPED);
-
-  flags = enter_critical_section();
-
-  /* Simply restart the thread.  If is was blocked before, it will awaken
-   * with errcode = EINTR and will appears as if it were awakened by a
-   * signal.  If pre-emption is not disabled this action could block this
-   * task here!
-   */
-
-  up_unblock_task(tcb);
-  leave_critical_section(flags);
-}
diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c
index 2a296ca166..cec1dc9804 100644
--- a/sched/semaphore/sem_waitirq.c
+++ b/sched/semaphore/sem_waitirq.c
@@ -50,6 +50,8 @@
  *   2. From logic associated with sem_timedwait().  This function is called
  *      when the timeout elapses without receiving the semaphore.
  *
+ *   Note: this function should used within critical_section
+ *
  * Input Parameters:
  *   wtcb    - A pointer to the TCB of the task that is waiting on a
  *             semphaphore, but has received a signal or timeout instead.
@@ -65,48 +67,33 @@
 
 void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 {
-  irqstate_t flags;
-
-  /* Disable interrupts.  This is necessary (unfortunately) because an
-   * interrupt handler may attempt to post the semaphore while we are
-   * doing this.
-   */
-
-  flags = enter_critical_section();
+  FAR sem_t *sem = wtcb->waitobj;
 
   /* It is possible that an interrupt/context switch beat us to the punch
    * and already changed the task's state.
    */
 
-  if (wtcb->task_state == TSTATE_WAIT_SEM)
-    {
-      FAR sem_t *sem = wtcb->waitobj;
-      DEBUGASSERT(sem != NULL && sem->semcount < 0);
+  DEBUGASSERT(sem != NULL && sem->semcount < 0);
 
-      /* Restore the correct priority of all threads that hold references
-       * to this semaphore.
-       */
-
-      nxsem_canceled(wtcb, sem);
-
-      /* And increment the count on the semaphore.  This releases the count
-       * that was taken by sem_post().  This count decremented the semaphore
-       * count to negative and caused the thread to be blocked in the first
-       * place.
-       */
+  /* Restore the correct priority of all threads that hold references
+   * to this semaphore.
+   */
 
-      sem->semcount++;
+  nxsem_canceled(wtcb, sem);
 
-      /* Mark the errno value for the thread. */
+  /* And increment the count on the semaphore.  This releases the count
+   * that was taken by sem_post().  This count decremented the semaphore
+   * count to negative and caused the thread to be blocked in the first
+   * place.
+   */
 
-      wtcb->errcode = errcode;
+  sem->semcount++;
 
-      /* Restart the task. */
+  /* Mark the errno value for the thread. */
 
-      up_unblock_task(wtcb);
-    }
+  wtcb->errcode = errcode;
 
-  /* Interrupts may now be enabled. */
+  /* Restart the task. */
 
-  leave_critical_section(flags);
+  up_unblock_task(wtcb);
 }
diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c
index b54e5960a0..8a6d6719dd 100644
--- a/sched/signal/sig_dispatch.c
+++ b/sched/signal/sig_dispatch.c
@@ -430,6 +430,8 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info)
 
   if (masked == 0)
     {
+      flags = enter_critical_section();
+
       /* If the task is blocked waiting for a semaphore, then that task must
        * be unblocked when a signal is received.
        */
@@ -462,10 +464,12 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info)
 #ifdef HAVE_GROUP_MEMBERS
           group_continue(stcb);
 #else
-          nxsched_continue(stcb);
+          up_unblock_task(stcb);
 #endif
         }
 #endif
+
+      leave_critical_section(flags);
     }
 
   /* In case nxsig_ismember failed due to an invalid signal number */