From c93d9caa8b8be81f7e6faf9f2ca2ad16d4942ab8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 25 Apr 2016 15:28:57 +0000 Subject: py/gc: Make memory manager and garbage collector thread safe. By using a single, global mutex, all memory-related functions (alloc, free, realloc, collect, etc) are made thread safe. This means that only one thread can be in such a function at any one time. --- py/mpstate.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'py/mpstate.h') diff --git a/py/mpstate.h b/py/mpstate.h index 18bec09e42..f1f8fd9c57 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -29,6 +29,7 @@ #include #include "py/mpconfig.h" +#include "py/mpthread.h" #include "py/misc.h" #include "py/nlr.h" #include "py/obj.h" @@ -80,6 +81,11 @@ typedef struct _mp_state_mem_t { #if MICROPY_PY_GC_COLLECT_RETVAL size_t gc_collected; #endif + + #if MICROPY_PY_THREAD + // This is a global mutex used to make the GC thread-safe. + mp_thread_mutex_t gc_mutex; + #endif } mp_state_mem_t; // This structure hold runtime and VM information. It includes a section -- cgit v1.2.3