mm: Restore the return type of mm_lock from bool to int

Fix the issue reported here better:
https://github.com/apache/incubator-nuttx/pull/6995

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2022-11-06 06:44:47 +08:00
committed by Petro Karashchenko
parent 4cc13c19c6
commit b567e09c3c
4 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -240,7 +240,7 @@ typedef CODE void (*mmchunk_handler_t)(FAR struct mm_allocnode_s *node,
/* Functions contained in mm_lock.c *****************************************/ /* Functions contained in mm_lock.c *****************************************/
bool mm_lock(FAR struct mm_heap_s *heap); int mm_lock(FAR struct mm_heap_s *heap);
void mm_unlock(FAR struct mm_heap_s *heap); void mm_unlock(FAR struct mm_heap_s *heap);
/* Functions contained in mm_shrinkchunk.c **********************************/ /* Functions contained in mm_shrinkchunk.c **********************************/
+1 -1
View File
@@ -68,7 +68,7 @@ void mm_foreach(FAR struct mm_heap_s *heap, mmchunk_handler_t handler,
* Retake the mutex for each region to reduce latencies * Retake the mutex for each region to reduce latencies
*/ */
if (!mm_lock(heap)) if (mm_lock(heap) < 0)
{ {
return; return;
} }
+1 -1
View File
@@ -84,7 +84,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
return; return;
} }
if (mm_lock(heap) == false) if (mm_lock(heap) < 0)
{ {
/* Meet -ESRCH return, which means we are in situations /* Meet -ESRCH return, which means we are in situations
* during context switching(See mm_lock() & getpid()). * during context switching(See mm_lock() & getpid()).
+6 -6
View File
@@ -51,11 +51,11 @@
* heap - heap instance want to take mutex * heap - heap instance want to take mutex
* *
* Returned Value: * Returned Value:
* true if the lock can be taken, otherwise false. * 0 if the lock can be taken, otherwise negative errno.
* *
****************************************************************************/ ****************************************************************************/
bool mm_lock(FAR struct mm_heap_s *heap) int mm_lock(FAR struct mm_heap_s *heap)
{ {
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
/* Check current environment */ /* Check current environment */
@@ -67,11 +67,11 @@ bool mm_lock(FAR struct mm_heap_s *heap)
* Or, touch the heap internal data directly. * Or, touch the heap internal data directly.
*/ */
return !nxmutex_is_locked(&heap->mm_lock); return nxmutex_is_locked(&heap->mm_lock) ? -EAGAIN : 0;
#else #else
/* Can't take mutex in SMP interrupt handler */ /* Can't take mutex in SMP interrupt handler */
return false; return -EAGAIN;
#endif #endif
} }
else else
@@ -89,11 +89,11 @@ bool mm_lock(FAR struct mm_heap_s *heap)
if (getpid() < 0) if (getpid() < 0)
{ {
return false; return -ESRCH;
} }
else else
{ {
return nxmutex_lock(&heap->mm_lock) >= 0; return nxmutex_lock(&heap->mm_lock);
} }
} }