Skip to content

Commit

Permalink
mm: Add mm_lock_irq, mm_unlock_iq
Browse files Browse the repository at this point in the history
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
  • Loading branch information
W-M-R committed Jan 10, 2025
1 parent e5e9032 commit c96096e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 10 deletions.
2 changes: 2 additions & 0 deletions mm/mm_heap/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ typedef CODE void (*mm_node_handler_t)(FAR struct mm_allocnode_s *node,

int mm_lock(FAR struct mm_heap_s *heap);
void mm_unlock(FAR struct mm_heap_s *heap);
irqstate_t mm_lock_irq(FAR struct mm_heap_s *heap);
void mm_unlock_irq(FAR struct mm_heap_s *heap, irqstate_t state);

/* Functions contained in mm_shrinkchunk.c **********************************/

Expand Down
4 changes: 2 additions & 2 deletions mm/mm_heap/mm_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)

/* Delay the deallocation until a more appropriate time. */

flags = up_irq_save();
flags = mm_lock_irq(heap);

# ifdef CONFIG_DEBUG_ASSERTIONS
FAR struct mm_freenode_s *node;
Expand All @@ -65,7 +65,7 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)
heap->mm_delaycount[this_cpu()]++;
#endif

up_irq_restore(flags);
mm_unlock_irq(heap, flags);
#endif
}

Expand Down
28 changes: 28 additions & 0 deletions mm/mm_heap/mm_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,31 @@ void mm_unlock(FAR struct mm_heap_s *heap)

DEBUGVERIFY(nxmutex_unlock(&heap->mm_lock));
}

/****************************************************************************
* Name: mm_lock_irq
*
* Description:
* Locking by pausing interruption
*
****************************************************************************/

irqstate_t mm_lock_irq(FAR struct mm_heap_s *heap)
{
UNUSED(heap);
return up_irq_save();
}

/****************************************************************************
* Name: mm_unlock_irq
*
* Description:
* Release the lock by resuming the interrupt
*
****************************************************************************/

void mm_unlock_irq(FAR struct mm_heap_s *heap, irqstate_t state)
{
UNUSED(heap);
up_irq_restore(state);
}
6 changes: 3 additions & 3 deletions mm/mm_heap/mm_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static bool free_delaylist(FAR struct mm_heap_s *heap, bool force)

/* Move the delay list to local */

flags = up_irq_save();
flags = mm_lock_irq(heap);

tmp = heap->mm_delaylist[this_cpu()];

Expand All @@ -74,7 +74,7 @@ static bool free_delaylist(FAR struct mm_heap_s *heap, bool force)
(!force &&
heap->mm_delaycount[this_cpu()] < CONFIG_MM_FREE_DELAYCOUNT_MAX))
{
up_irq_restore(flags);
mm_unlock_irq(heap, flags);
return false;
}

Expand All @@ -83,7 +83,7 @@ static bool free_delaylist(FAR struct mm_heap_s *heap, bool force)

heap->mm_delaylist[this_cpu()] = NULL;

up_irq_restore(flags);
mm_unlock_irq(heap, flags);

/* Test if the delayed is empty */

Expand Down
38 changes: 33 additions & 5 deletions mm/tlsf/mm_tlsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ static void mm_delayfree(struct mm_heap_s *heap, void *mem, bool delay);
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: mm_lock_irq
*
* Description:
* Locking by pausing interruption
*
****************************************************************************/

static irqstate_t mm_lock_irq(FAR struct mm_heap_s *heap)
{
UNUSED(heap);
return up_irq_save();
}

/****************************************************************************
* Name: mm_unlock_irq
*
* Description:
* Release the lock by resuming the interrupt
*
****************************************************************************/

static void mm_unlock_irq(FAR struct mm_heap_s *heap, irqstate_t state)
{
UNUSED(heap);
up_irq_restore(state);
}

static void memdump_allocnode(FAR void *ptr, size_t size)
{
#if CONFIG_MM_BACKTRACE < 0
Expand Down Expand Up @@ -301,7 +329,7 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)

/* Delay the deallocation until a more appropriate time. */

flags = up_irq_save();
flags = mm_lock_irq(heap);

tmp->flink = heap->mm_delaylist[this_cpu()];
heap->mm_delaylist[this_cpu()] = tmp;
Expand All @@ -310,7 +338,7 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)
heap->mm_delaycount[this_cpu()]++;
#endif

up_irq_restore(flags);
mm_unlock_irq(heap, flags);
#endif
}

Expand All @@ -327,7 +355,7 @@ static bool free_delaylist(FAR struct mm_heap_s *heap, bool force)

/* Move the delay list to local */

flags = up_irq_save();
flags = mm_unlock_irq(heap);

tmp = heap->mm_delaylist[this_cpu()];

Expand All @@ -336,7 +364,7 @@ static bool free_delaylist(FAR struct mm_heap_s *heap, bool force)
(!force &&
heap->mm_delaycount[this_cpu()] < CONFIG_MM_FREE_DELAYCOUNT_MAX))
{
up_irq_restore(flags);
mm_unlock_irq(heap, flags);
return false;
}

Expand All @@ -345,7 +373,7 @@ static bool free_delaylist(FAR struct mm_heap_s *heap, bool force)

heap->mm_delaylist[this_cpu()] = NULL;

up_irq_restore(flags);
mm_unlock_irq(heap, flags);

/* Test if the delayed is empty */

Expand Down

0 comments on commit c96096e

Please sign in to comment.