From 07f031c70840352893e7137abbf7d564c3d4a0b7 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 17 Jul 2020 17:02:13 -0700 Subject: Add ignore() and fix docs --- shared-module/memorymonitor/AllocationAlarm.c | 20 ++++++++++++++------ shared-module/memorymonitor/AllocationAlarm.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'shared-module') diff --git a/shared-module/memorymonitor/AllocationAlarm.c b/shared-module/memorymonitor/AllocationAlarm.c index ed7ab75ab..35f4e4c63 100644 --- a/shared-module/memorymonitor/AllocationAlarm.c +++ b/shared-module/memorymonitor/AllocationAlarm.c @@ -37,6 +37,10 @@ void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocation self->previous = NULL; } +void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t* self, mp_int_t count) { + self->count = count; +} + void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t* self) { // Check to make sure we aren't already paused. We can be if we're exiting from an exception we // caused. @@ -67,12 +71,16 @@ void memorymonitor_allocationalarms_allocation(size_t block_count) { // Hold onto next in case we remove the alarm from the list. memorymonitor_allocationalarm_obj_t* next = alarm->next; if (block_count >= alarm->minimum_block_count) { - // Uncomment the breakpoint below if you want to use a C debugger to figure out the C - // call stack for an allocation. - // asm("bkpt"); - // Pause now because we may alert when throwing the exception too. - common_hal_memorymonitor_allocationalarm_pause(alarm); - alert_count++; + if (alarm->count > 0) { + alarm->count--; + } else { + // Uncomment the breakpoint below if you want to use a C debugger to figure out the C + // call stack for an allocation. + // asm("bkpt"); + // Pause now because we may alert when throwing the exception too. + common_hal_memorymonitor_allocationalarm_pause(alarm); + alert_count++; + } } alarm = next; } diff --git a/shared-module/memorymonitor/AllocationAlarm.h b/shared-module/memorymonitor/AllocationAlarm.h index 95381c660..172c24f6c 100644 --- a/shared-module/memorymonitor/AllocationAlarm.h +++ b/shared-module/memorymonitor/AllocationAlarm.h @@ -39,6 +39,7 @@ typedef struct _memorymonitor_allocationalarm_obj_t memorymonitor_allocationalar typedef struct _memorymonitor_allocationalarm_obj_t { mp_obj_base_t base; size_t minimum_block_count; + mp_int_t count; // Store the location that points to us so we can remove ourselves. memorymonitor_allocationalarm_obj_t** previous; memorymonitor_allocationalarm_obj_t* next; -- cgit v1.2.3