Skip to content

Commit d4d1d47

Browse files
projectgusdpgeorge
authored andcommitted
esp32: Simplify thread cleanup.
Now we only support the case of !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP, can simplify the cleanup code. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent d90aff5 commit d4d1d47

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

ports/esp32/mpthreadport.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@
4141
#define MP_THREAD_DEFAULT_STACK_SIZE (MP_THREAD_MIN_STACK_SIZE + MICROPY_STACK_CHECK_MARGIN)
4242
#define MP_THREAD_PRIORITY (ESP_TASK_PRIO_MIN + 1)
4343

44-
#if !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
45-
#define FREERTOS_TASK_DELETE_HOOK vTaskPreDeletionHook
46-
#else
47-
#define FREERTOS_TASK_DELETE_HOOK vPortCleanUpTCB
48-
#endif
49-
5044
// this structure forms a linked list, one node per active thread
5145
typedef struct _mp_thread_t {
5246
TaskHandle_t id; // system id of thread
@@ -76,7 +70,7 @@ void mp_thread_init(void *stack, uint32_t stack_len) {
7670
// memory barrier to ensure above data is committed
7771
__sync_synchronize();
7872

79-
// FREERTOS_TASK_DELETE_HOOK needs the thread ready after thread_mutex is ready
73+
// vTaskPreDeletionHook needs the thread ready after thread_mutex is ready
8074
thread = &thread_entry0;
8175
}
8276

@@ -180,9 +174,10 @@ void mp_thread_finish(void) {
180174
mp_thread_mutex_unlock(&thread_mutex);
181175
}
182176

183-
// This is called from the FreeRTOS idle task and is not within Python context,
184-
// so MP_STATE_THREAD is not valid and it does not have the GIL.
185-
void FREERTOS_TASK_DELETE_HOOK(void *tcb) {
177+
// This is called either from vTaskDelete() or from the FreeRTOS idle task, so
178+
// may not be within Python context. Therefore MP_STATE_THREAD may not be valid
179+
// and it does not have the GIL.
180+
void vTaskPreDeletionHook(void *tcb) {
186181
if (thread == NULL) {
187182
// threading not yet initialised
188183
return;
@@ -243,15 +238,15 @@ void mp_thread_deinit(void) {
243238
// No tasks left to delete
244239
break;
245240
} else {
246-
// Call FreeRTOS to delete the task (it will call FREERTOS_TASK_DELETE_HOOK)
241+
// Call FreeRTOS to delete the task (it will call vTaskPreDeletionHook)
247242
vTaskDelete(id);
248243
}
249244
}
250245
}
251246

252247
#else
253248

254-
void FREERTOS_TASK_DELETE_HOOK(void *tcb) {
249+
void vTaskPreDeletionHook(void *tcb) {
255250
}
256251

257252
#endif // MICROPY_PY_THREAD

0 commit comments

Comments
 (0)