pkarashchenko commented on a change in pull request #5539:
URL: https://github.com/apache/incubator-nuttx/pull/5539#discussion_r809741780



##########
File path: mm/mm_heap/mm_sem.c
##########
@@ -80,9 +80,21 @@ bool mm_takesemaphore(FAR struct mm_heap_s *heap)
 
   if (up_interrupt_context())
     {
-      /* Can't take semaphore in the interrupt handler */
+#if !defined(CONFIG_SMP) && defined(CONFIG_DEBUG_MM)
+      int val;
+
+      /* Check the semaphore value, if held by someone, then return false.
+       * Else, we can take it, return true.
+       */
+
+      _SEM_GETVALUE(&heap->mm_semaphore, &val);

Review comment:
       There is a special case for `mm_free()`:
   ```
     if (mm_takesemaphore(heap) == false)
       {
         kasan_unpoison(mem, mm_malloc_size(mem));
   
         /* We are in IDLE task & can't get sem, or meet -ESRCH return,
          * which means we are in situations during context switching(See
          * mm_takesemaphore() & getpid()). Then add to the delay list.
          */
   
         mm_add_delaylist(heap, mem);
         return;
       }
   ```
   I think we should try to get back `return _SEM_TRYWAIT(&heap->mm_semaphore) 
>= 0;` in case of `else if (sched_idletask())`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to