From 68d66148ad43f294c2067f5faff0d1a94c3dd9f1 Mon Sep 17 00:00:00 2001 From: ligd Date: Fri, 16 Apr 2021 18:08:21 +0800 Subject: [PATCH] mm: idle check heap use mm_trysemaphore Change-Id: I92e1df572fa6cd801b10e5b06e7b04d450b3e3fb Signed-off-by: ligd (cherry picked from commit bc9a5d1ca9656f6effd3a419cc2488586dfb1489) --- mm/mm_heap/mm_checkcorruption.c | 19 +++++++++---------- sched/init/nx_start.c | 7 ++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mm/mm_heap/mm_checkcorruption.c b/mm/mm_heap/mm_checkcorruption.c index 5bafdbae0c..e45fe27bb5 100644 --- a/mm/mm_heap/mm_checkcorruption.c +++ b/mm/mm_heap/mm_checkcorruption.c @@ -66,15 +66,13 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap) for (region = 0; region < heap_impl->mm_nregions; region++) #endif { - irqstate_t flags = 0; - prev = NULL; /* Visit each node in the region * Retake the semaphore for each region to reduce latencies */ - if (up_interrupt_context() || sched_idletask()) + if (up_interrupt_context()) { if (heap_impl->mm_counts_held) { @@ -84,8 +82,13 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap) return; #endif } - - flags = enter_critical_section(); + } + else if (sched_idletask()) + { + if (mm_trysemaphore(heap)) + { + return; + } } else { @@ -122,11 +125,7 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap) assert(node == heap_impl->mm_heapend[region]); - if (up_interrupt_context() || sched_idletask()) - { - leave_critical_section(flags); - } - else + if (!up_interrupt_context()) { mm_givesemaphore(heap); } diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index 109412546f..7840387e7f 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -805,19 +805,20 @@ void nx_start(void) /* Check stack in idle thread */ - flags = enter_critical_section(); - for (i = 0; i < CONFIG_MAX_TASKS && g_pidhash[i].tcb; i++) { + flags = enter_critical_section(); + if (up_check_tcbstack_remain(g_pidhash[i].tcb) <= 0) { _alert("Stack check failed, pid %d, name %s\n", g_pidhash[i].tcb->pid, g_pidhash[i].tcb->name); PANIC(); } + + leave_critical_section(flags); } - leave_critical_section(flags); #endif /* Check heap in idle thread */