summaryrefslogtreecommitdiffstatshomepage
path: root/py/mpstate.h
diff options
context:
space:
mode:
Diffstat (limited to 'py/mpstate.h')
-rw-r--r--py/mpstate.h51
1 files changed, 40 insertions, 11 deletions
diff --git a/py/mpstate.h b/py/mpstate.h
index 0e77e65833..281795773f 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
@@ -91,9 +97,6 @@ typedef struct _mp_state_vm_t {
// this must start at the start of this structure
//
- // Note: nlr asm code has the offset of this hard-coded
- nlr_buf_t *nlr_top;
-
qstr_pool_t *last_pool;
// non-heap memory for creating an exception if we can't allocate RAM
@@ -140,6 +143,7 @@ typedef struct _mp_state_vm_t {
#if MICROPY_PY_OS_DUPTERM
mp_obj_t term_obj;
+ mp_obj_t dupterm_arr_obj;
#endif
#if MICROPY_PY_LWIP_SLIP
@@ -161,12 +165,9 @@ typedef struct _mp_state_vm_t {
size_t qstr_last_alloc;
size_t qstr_last_used;
- // Stack top at the start of program
- // Note: this entry is used to locate the end of the root pointer section.
- char *stack_top;
-
- #if MICROPY_STACK_CHECK
- mp_uint_t stack_limit;
+ #if MICROPY_PY_THREAD
+ // This is a global mutex used to make qstr interning thread-safe.
+ mp_thread_mutex_t qstr_mutex;
#endif
mp_uint_t mp_optimise_value;
@@ -175,9 +176,29 @@ typedef struct _mp_state_vm_t {
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0
mp_int_t mp_emergency_exception_buf_size;
#endif
+
+ #if MICROPY_PY_THREAD_GIL
+ // This is a global mutex used to make the VM/runtime thread-safe.
+ mp_thread_mutex_t gil_mutex;
+ #endif
} mp_state_vm_t;
-// This structure combines the above 2 structures, and adds the local
+// This structure holds state that is specific to a given thread.
+// Everything in this structure is scanned for root pointers.
+typedef struct _mp_state_thread_t {
+ // Note: nlr asm code has the offset of this hard-coded
+ nlr_buf_t *nlr_top; // ROOT POINTER
+
+ // Stack top at the start of program
+ // Note: this entry is used to locate the end of the root pointer section.
+ char *stack_top;
+
+ #if MICROPY_STACK_CHECK
+ size_t stack_limit;
+ #endif
+} mp_state_thread_t;
+
+// This structure combines the above 3 structures, and adds the local
// and global dicts.
// Note: if this structure changes then revisit all nlr asm code since they
// have the offset of nlr_top hard-coded.
@@ -185,7 +206,8 @@ typedef struct _mp_state_ctx_t {
// these must come first for root pointer scanning in GC to work
mp_obj_dict_t *dict_locals;
mp_obj_dict_t *dict_globals;
- // this must come next for root pointer scanning in GC to work
+ // these must come next in this order for root pointer scanning in GC to work
+ mp_state_thread_t thread;
mp_state_vm_t vm;
mp_state_mem_t mem;
} mp_state_ctx_t;
@@ -196,4 +218,11 @@ extern mp_state_ctx_t mp_state_ctx;
#define MP_STATE_VM(x) (mp_state_ctx.vm.x)
#define MP_STATE_MEM(x) (mp_state_ctx.mem.x)
+#if MICROPY_PY_THREAD
+extern mp_state_thread_t *mp_thread_get_state(void);
+#define MP_STATE_THREAD(x) (mp_thread_get_state()->x)
+#else
+#define MP_STATE_THREAD(x) (mp_state_ctx.thread.x)
+#endif
+
#endif // __MICROPY_INCLUDED_PY_MPSTATE_H__