Skip to content

Commit

Permalink
esp32/mpthreadport: Don't explicitly free thread struct in TCB cleanup.
Browse files Browse the repository at this point in the history
Because vPortCleanUpTCB runs on the FreeRTOS idle task and cannot execute
any VM or runtime related code like freeing memory.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed May 8, 2021
1 parent fd24e64 commit 31e0b8c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ports/esp32/mpthreadport.c
Expand Up @@ -166,6 +166,8 @@ void mp_thread_finish(void) {
mp_thread_mutex_unlock(&thread_mutex);
}

// This is called from the FreeRTOS idle task and is not within Python context,
// so MP_STATE_THREAD is not valid and it does not have the GIL.
void vPortCleanUpTCB(void *tcb) {
if (thread == NULL) {
// threading not yet initialised
Expand All @@ -182,8 +184,7 @@ void vPortCleanUpTCB(void *tcb) {
// move the start pointer
thread = th->next;
}
// explicitly release all its memory
m_del(thread_t, th, 1);
// The "th" memory will eventually be reclaimed by the GC.
break;
}
}
Expand Down

0 comments on commit 31e0b8c

Please sign in to comment.