summaryrefslogtreecommitdiffstatshomepage
path: root/py/mpstate.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-04-25 15:28:57 +0000
committerDamien George <damien.p.george@gmail.com>2016-06-28 11:28:49 +0100
commitc93d9caa8b8be81f7e6faf9f2ca2ad16d4942ab8 (patch)
tree8bc6f5fd0363d3f7135d1e47d0ba13a5cf7c9a6d /py/mpstate.h
parent34fc006f5e75f064f3aad9ccc98963dc2fa01e25 (diff)
downloadmicropython-c93d9caa8b8be81f7e6faf9f2ca2ad16d4942ab8.tar.gz
micropython-c93d9caa8b8be81f7e6faf9f2ca2ad16d4942ab8.zip
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.
Diffstat (limited to 'py/mpstate.h')
-rw-r--r--py/mpstate.h6
1 files changed, 6 insertions, 0 deletions
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 <stdint.h>
#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