mm: handle take mm sem in IRQ

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-02-14 16:47:42 +08:00 committed by Alan Carvalho de Assis
parent b60b6120de
commit 0169a51220
2 changed files with 27 additions and 3 deletions

View File

@ -68,7 +68,10 @@ void mm_foreach(FAR struct mm_heap_s *heap, mmchunk_handler_t handler,
* Retake the semaphore for each region to reduce latencies * Retake the semaphore for each region to reduce latencies
*/ */
DEBUGVERIFY(mm_takesemaphore(heap)); if (!mm_takesemaphore(heap))
{
return;
}
for (node = heap->mm_heapstart[region]; for (node = heap->mm_heapstart[region];
node < heap->mm_heapend[region]; node < heap->mm_heapend[region];

View File

@ -104,9 +104,23 @@ bool mm_takesemaphore(FAR struct mm_heap_s *heap)
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
else if (sched_idletask()) else if (sched_idletask())
{ {
/* Try to take the semaphore */ return false;
}
else if (up_interrupt_context())
{
#ifdef CONFIG_SMP
return false;
#else
int val;
return _SEM_TRYWAIT(&heap->mm_semaphore) >= 0; /* Check the semaphore value, if held by someone, then return false.
* Else, we can take it, return true.
*/
_SEM_GETVALUE(&heap->mm_semaphore, &val);
return val > 0;
#endif
} }
#endif #endif
else else
@ -145,5 +159,12 @@ bool mm_takesemaphore(FAR struct mm_heap_s *heap)
void mm_givesemaphore(FAR struct mm_heap_s *heap) void mm_givesemaphore(FAR struct mm_heap_s *heap)
{ {
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
if (up_interrupt_context())
{
return;
}
#endif
DEBUGVERIFY(_SEM_POST(&heap->mm_semaphore)); DEBUGVERIFY(_SEM_POST(&heap->mm_semaphore));
} }