summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/gc.c7
-rw-r--r--py/gc.h3
2 files changed, 10 insertions, 0 deletions
diff --git a/py/gc.c b/py/gc.c
index e92b81ece..0fc43ef49 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -362,6 +362,13 @@ void gc_collect_end(void) {
GC_EXIT();
}
+void gc_sweep_all(void) {
+ GC_ENTER();
+ MP_STATE_MEM(gc_lock_depth)++;
+ MP_STATE_MEM(gc_stack_overflow) = 0;
+ gc_collect_end();
+}
+
void gc_info(gc_info_t *info) {
GC_ENTER();
info->total = MP_STATE_MEM(gc_pool_end) - MP_STATE_MEM(gc_pool_start);
diff --git a/py/gc.h b/py/gc.h
index 739349c1f..73d86e6c3 100644
--- a/py/gc.h
+++ b/py/gc.h
@@ -45,6 +45,9 @@ void gc_collect_start(void);
void gc_collect_root(void **ptrs, size_t len);
void gc_collect_end(void);
+// Use this function to sweep the whole heap and run all finalisers
+void gc_sweep_all(void);
+
void *gc_alloc(size_t n_bytes, bool has_finaliser);
void gc_free(void *ptr); // does not call finaliser
size_t gc_nbytes(const void *ptr);