Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mm/mm_heap/mm_foreach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

DEBUGVERIFY(mm_takesemaphore(heap));
if (!mm_takesemaphore(heap))
{
return;
}

for (node = heap->mm_heapstart[region];
node < heap->mm_heapend[region];
Expand Down
25 changes: 23 additions & 2 deletions mm/mm_heap/mm_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,23 @@ bool mm_takesemaphore(FAR struct mm_heap_s *heap)
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
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
else
Expand Down Expand Up @@ -145,5 +159,12 @@ bool mm_takesemaphore(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));
}