diff options
author | Angus Gratton <angus@redyak.com.au> | 2024-12-10 14:50:42 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-02-03 15:02:02 +1100 |
commit | 4bcbe88e74de245fdee029b6a0746e3485d82a7e (patch) | |
tree | 400657f71958868f75558374efa3146394561dd3 /py/gc.c | |
parent | 40e1c111e17864044190596dff6d32955d11280c (diff) | |
download | micropython-4bcbe88e74de245fdee029b6a0746e3485d82a7e.tar.gz micropython-4bcbe88e74de245fdee029b6a0746e3485d82a7e.zip |
py: Add optional support for recursive mutexes, use for gc mutex.
Enabled by default if using threading and no GIL
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py/gc.c')
-rw-r--r-- | py/gc.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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 |