mm/mm_heap/mm_sem.c: Defer freeing if mm is held by a not running task. When the holder is running we can add a holder count. If there is no holder OR it is not running we want to try to take the semaphore. There will not be a count if the task is the holder and not running because it already holds the count. This will result it the deferred free. We will take it when not held and do the free when we can get the count because there was no holder.

This commit is contained in:
David Sidrane 2018-12-20 13:39:06 -06:00 committed by Gregory Nutt
parent 86508a0e85
commit 43d37c866b

View File

@ -76,8 +76,7 @@
# define _SEM_GETERROR(r) (r) = -errno
#endif
/* Define the following to enable semaphore state monitoring */
//#define MONITOR_MM_SEMAPHORE 1
/* Define MONITOR_MM_SEMAPHORE to enable semaphore state monitoring */
#ifdef MONITOR_MM_SEMAPHORE
# include <debug.h>
@ -151,16 +150,10 @@ int mm_trysemaphore(FAR struct mm_heap_s *heap)
* corruption and must be avoided.
*/
if (rtcb->task_state != TSTATE_TASK_RUNNING)
{
ret = -EINVAL;
goto errout;
}
/* Do I already have the semaphore? */
my_pid = rtcb->pid;
if (heap->mm_holder == my_pid)
if (heap->mm_holder == my_pid && rtcb->task_state == TSTATE_TASK_RUNNING)
{
/* Yes, just increment the number of references that I have */