GUIDINGLI edited a comment on pull request #5504:
URL: https://github.com/apache/incubator-nuttx/pull/5504#issuecomment-1043876145


   No, I don't think this crash caused by this PR.
   For merge reason (my branch code base is no with 
b316611ef0bd616609285c26dbc98fcf83b8aecb).
   This PR is not reach my purpose.
   
   There still have `if (up_interrupt_context)` branch at top of 
`mm_takesemaphore()`.
   In another word, this PR, only do the `mm_givesemaphore()` return when meet 
`up_interrupt_context`. 
   This has no harmful for the logic.
   
   So, could you please run more test without this PR ?  Guess will also have 
the problem.
   
    ```
   76 bool mm_takesemaphore(FAR struct mm_heap_s *heap)
    77 {
    78 #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
    79   /* Check current environment */
    80 
    81   if (up_interrupt_context())                                // same 
with 105, will fix it later
    82     {
    83       /* Can't take semaphore in the interrupt handler */
    84 
    85       return false;
    86     }
    87   else
    88 #endif
    89 
    90   /* getpid() returns the task ID of the task at the head of the 
ready-to-
    91    * run task list.  mm_takesemaphore() may be called during context
    92    * switches.  There are certain situations during context switching 
when
    93    * the OS data structures are in flux and then can't be freed 
immediately
    94    * (e.g. the running thread stack).
    95    *
    96    * This is handled by getpid() to return the special value -ESRCH to
    97    * indicate this special situation.
    98    */
    99 
   100   if (getpid() < 0)
   101     {
   102       return false;
   103     }
   104 #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
   105   else if (sched_idletask())
   106     {
   107       return false;
   108     }
   109   else if (up_interrupt_context())
   110     {
   111 #ifdef CONFIG_SMP
   112       return false;
   113 #else
   114       int val;
   115 
   116       /* Check the semaphore value, if held by someone, then return 
false.
   117        * Else, we can take it, return true.
   118        */
   119 
   120       _SEM_GETVALUE(&heap->mm_semaphore, &val);
   121 
   122       return val > 0;
   123 #endif
   ```
   


-- 
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