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
6 changes: 3 additions & 3 deletions mm/mm_heap/mm_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
{
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.
/* Meet -ESRCH return, which means we are in situations
* during context switching(See mm_takesemaphore() & getpid()).
* Then add to the delay list.
*/
Comment thread
masayuki2009 marked this conversation as resolved.

mm_add_delaylist(heap, mem);
Expand Down
36 changes: 13 additions & 23 deletions mm/mm_heap/mm_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
int val;

/* Check the semaphore value, if held by someone, then return false.
* Or, touch the heap internal data directly.
*/

_SEM_GETVALUE(&heap->mm_semaphore, &val);
Comment thread
xiaoxiang781216 marked this conversation as resolved.

return val > 0;
#else
/* Can't take semaphore in SMP interrupt handler */

return false;
#endif
}
else
#endif
Expand All @@ -101,28 +113,6 @@ bool mm_takesemaphore(FAR struct mm_heap_s *heap)
{
return false;
}
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
else if (sched_idletask())
{
return false;
}
else if (up_interrupt_context())
{
#ifdef CONFIG_SMP
return false;
#else
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);

return val > 0;
#endif
}
#endif
else
{
int ret;
Expand Down