From caee5581c2b8546a989951103427d0dd9b2b87c5 Mon Sep 17 00:00:00 2001 From: ligd Date: Mon, 27 Sep 2021 15:52:03 +0800 Subject: [PATCH] sem: remove limitation of irq context when do sem_trywait Change-Id: I818c349d9396743877e99c5b04fc7265750a5ec3 Signed-off-by: ligd --- mm/mm_heap/mm_sem.c | 14 +------------- sched/semaphore/sem_trywait.c | 4 ---- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index a4d4e869c7c..b62983a809d 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -75,18 +75,6 @@ void mm_seminitialize(FAR struct mm_heap_s *heap) bool mm_takesemaphore(FAR struct mm_heap_s *heap) { -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) - /* Check current environment */ - - if (up_interrupt_context()) - { - /* Can't take semaphore in the interrupt handler */ - - return false; - } - else -#endif - /* getpid() returns the task ID of the task at the head of the ready-to- * run task list. mm_takesemaphore() may be called during context * switches. There are certain situations during context switching when @@ -102,7 +90,7 @@ bool mm_takesemaphore(FAR struct mm_heap_s *heap) return false; } #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) - else if (sched_idletask()) + else if (sched_idletask() || up_interrupt_context()) { /* Try to take the semaphore */ diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index 3648aac26c1..1d973a12630 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -69,10 +69,6 @@ int nxsem_trywait(FAR sem_t *sem) irqstate_t flags; int ret; - /* This API should not be called from interrupt handlers */ - - DEBUGASSERT(sem != NULL && up_interrupt_context() == false); - if (sem != NULL) { /* The following operations must be performed with interrupts disabled