@@ -61,8 +61,8 @@ STATIC thread_t *thread_root; // root pointer, handled by mp_thread_gc_others
6161/**
6262 * thread port initialization
6363 *
64- * @param stack MicroPython main thread stack
65- * @param stack_len MicroPython main thread stack
64+ * @param stack MicroPython main thread stack start address
65+ * @param stack_len number of words in the stack
6666 */
6767void mp_thread_init (void * stack , uint32_t stack_len ) {
6868 mp_thread_set_state (& mp_state_ctx .thread );
@@ -82,20 +82,18 @@ void mp_thread_gc_others(void) {
8282
8383 mp_thread_mutex_lock (& thread_mutex , 1 );
8484 for (thread_t * th = thread_root ; th != NULL ; th = th -> next ) {
85- if (th == & thread_root_node ) {
86- continue ;
85+ // the root node not using the mpy heap
86+ if (th != & thread_root_node ) {
87+ gc_collect_root ((void * * )& th , 1 );
88+ gc_collect_root (& th -> arg , 1 ); // probably not needed
8789 }
88- gc_collect_root ((void * * )& th , 1 );
89- gc_collect_root (& th -> arg , 1 ); // probably not needed
9090
91- if (th -> id == rt_thread_self () ) {
91+ if (th -> status == MP_THREAD_STATUS_READY ) {
9292 continue ;
9393 }
94- if (th -> status != MP_THREAD_STATUS_FINISH ) {
95- continue ;
96- }
97- gc_collect_root ((void * * )& th -> id , 1 ); // probably not needed
98- gc_collect_root ((void * * )& th -> stack , th -> stack_len ); // probably not needed
94+
95+ gc_collect_root ((void * * ) & th -> id , 1 ); // probably not needed
96+ gc_collect_root (th -> stack , th -> stack_len ); // probably not needed
9997 }
10098 mp_thread_mutex_unlock (& thread_mutex );
10199}
@@ -150,7 +148,7 @@ void mp_thread_create_ex(void *(*entry)(void*), void *arg, size_t *stack_size, i
150148 // add thread to linked list of all threads
151149 th -> status = MP_THREAD_STATUS_READY ;
152150 th -> arg = arg ;
153- th -> stack_len = * stack_size ;
151+ th -> stack_len = * stack_size / 4 ;
154152 th -> next = thread_root ;
155153 thread_root = th ;
156154
0 commit comments