@@ -91,9 +91,6 @@ typedef struct _mp_state_vm_t {
9191 // this must start at the start of this structure
9292 //
9393
94- // Note: nlr asm code has the offset of this hard-coded
95- nlr_buf_t * nlr_top ;
96-
9794 qstr_pool_t * last_pool ;
9895
9996 // non-heap memory for creating an exception if we can't allocate RAM
@@ -161,14 +158,6 @@ typedef struct _mp_state_vm_t {
161158 size_t qstr_last_alloc ;
162159 size_t qstr_last_used ;
163160
164- // Stack top at the start of program
165- // Note: this entry is used to locate the end of the root pointer section.
166- char * stack_top ;
167-
168- #if MICROPY_STACK_CHECK
169- mp_uint_t stack_limit ;
170- #endif
171-
172161 mp_uint_t mp_optimise_value ;
173162
174163 // size of the emergency exception buf, if it's dynamically allocated
@@ -177,15 +166,31 @@ typedef struct _mp_state_vm_t {
177166 #endif
178167} mp_state_vm_t ;
179168
180- // This structure combines the above 2 structures, and adds the local
169+ // This structure holds state that is specific to a given thread.
170+ // Everything in this structure is scanned for root pointers.
171+ typedef struct _mp_state_thread_t {
172+ // Note: nlr asm code has the offset of this hard-coded
173+ nlr_buf_t * nlr_top ; // ROOT POINTER
174+
175+ // Stack top at the start of program
176+ // Note: this entry is used to locate the end of the root pointer section.
177+ char * stack_top ;
178+
179+ #if MICROPY_STACK_CHECK
180+ size_t stack_limit ;
181+ #endif
182+ } mp_state_thread_t ;
183+
184+ // This structure combines the above 3 structures, and adds the local
181185// and global dicts.
182186// Note: if this structure changes then revisit all nlr asm code since they
183187// have the offset of nlr_top hard-coded.
184188typedef struct _mp_state_ctx_t {
185189 // these must come first for root pointer scanning in GC to work
186190 mp_obj_dict_t * dict_locals ;
187191 mp_obj_dict_t * dict_globals ;
188- // this must come next for root pointer scanning in GC to work
192+ // these must come next in this order for root pointer scanning in GC to work
193+ mp_state_thread_t thread ;
189194 mp_state_vm_t vm ;
190195 mp_state_mem_t mem ;
191196} mp_state_ctx_t ;
@@ -196,4 +201,6 @@ extern mp_state_ctx_t mp_state_ctx;
196201#define MP_STATE_VM (x ) (mp_state_ctx.vm.x)
197202#define MP_STATE_MEM (x ) (mp_state_ctx.mem.x)
198203
204+ #define MP_STATE_THREAD (x ) (mp_state_ctx.thread.x)
205+
199206#endif // __MICROPY_INCLUDED_PY_MPSTATE_H__
0 commit comments