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/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 40c6af6dec Revert "libs/libc/semaphore: Fix DEBUGASSERTS"
40c6af6dec is described below

commit 40c6af6dec0d769ac57f69e89709f9d6310ee0c6
Author: Tiago Medicci Serrano <tiago.medi...@espressif.com>
AuthorDate: Mon Apr 14 13:52:38 2025 -0300

    Revert "libs/libc/semaphore: Fix DEBUGASSERTS"
    
    This reverts commit 300992203ac0a14602c8cf744ec87d5525fe4dfb to
    fix a problem with `esp32-devkitc:blewifi`, which fails to boot up
    if `CONFIG_DEBUG_ASSERTIONS=y`.
    
    Introduced by https://github.com/apache/nuttx/pull/16176 with the
    following description:
    
    > The DEBUGASSERTS in nxsem_wait and nxsem_trywait are
    non-functional, they don't check anything. These were broken in
    previous commits.
    
    The above statements are not valid. Originally, there was no
    problem calling `nxsem_trywait` from the interrupt and the
    `DEBUGASSERT` simply checked a corner case: if ran from the
    interrupt context, the current (interrupted) task may be the idle
    task. This case is allowed only if called from an interrupt and
    that's what the original commit checks with:
    
    ```
      DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask() ||
                  up_interrupt_context());
    ```
---
 libs/libc/semaphore/sem_trywait.c | 7 ++++---
 libs/libc/semaphore/sem_wait.c    | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/libs/libc/semaphore/sem_trywait.c 
b/libs/libc/semaphore/sem_trywait.c
index 87e3fb8d55..4cd4b1c59c 100644
--- a/libs/libc/semaphore/sem_trywait.c
+++ b/libs/libc/semaphore/sem_trywait.c
@@ -106,12 +106,13 @@ int sem_trywait(FAR sem_t *sem)
 
 int nxsem_trywait(FAR sem_t *sem)
 {
+  DEBUGASSERT(sem != NULL);
+
   /* This API should not be called from the idleloop or interrupt */
 
 #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
-  DEBUGASSERT(sem != NULL);
-  DEBUGASSERT(!up_interrupt_context());
-  DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask());
+  DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask() ||
+              up_interrupt_context());
 #endif
 
   /* We don't do atomic fast path in case of LIBC_ARCH_ATOMIC because that
diff --git a/libs/libc/semaphore/sem_wait.c b/libs/libc/semaphore/sem_wait.c
index 0c56db9d96..77e03377d6 100644
--- a/libs/libc/semaphore/sem_wait.c
+++ b/libs/libc/semaphore/sem_wait.c
@@ -134,12 +134,13 @@ errout_with_cancelpt:
 
 int nxsem_wait(FAR sem_t *sem)
 {
+  DEBUGASSERT(sem != NULL);
+
   /* This API should not be called from the idleloop or interrupt */
 
 #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
-  DEBUGASSERT(sem != NULL);
-  DEBUGASSERT(!up_interrupt_context());
-  DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask());
+  DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask() ||
+              up_interrupt_context());
 #endif
 
   /* We don't do atomic fast path in case of LIBC_ARCH_ATOMIC because that

Reply via email to