summaryrefslogtreecommitdiffstatshomepage
path: root/py/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/gc.c')
-rw-r--r--py/gc.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/py/gc.c b/py/gc.c
index 3d48e06249..6a3f48ac3c 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -113,9 +113,12 @@
#endif
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
-#define GC_ENTER() mp_thread_mutex_lock(&MP_STATE_MEM(gc_mutex), 1)
-#define GC_EXIT() mp_thread_mutex_unlock(&MP_STATE_MEM(gc_mutex))
+#define GC_MUTEX_INIT() mp_thread_recursive_mutex_init(&MP_STATE_MEM(gc_mutex))
+#define GC_ENTER() mp_thread_recursive_mutex_lock(&MP_STATE_MEM(gc_mutex), 1)
+#define GC_EXIT() mp_thread_recursive_mutex_unlock(&MP_STATE_MEM(gc_mutex))
#else
+// Either no threading, or assume callers to gc_collect() hold the GIL
+#define GC_MUTEX_INIT()
#define GC_ENTER()
#define GC_EXIT()
#endif
@@ -210,9 +213,7 @@ void gc_init(void *start, void *end) {
MP_STATE_MEM(gc_alloc_amount) = 0;
#endif
- #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
- mp_thread_mutex_init(&MP_STATE_MEM(gc_mutex));
- #endif
+ GC_MUTEX_INIT();
}
#if MICROPY_GC_SPLIT_HEAP