From be5657b64ff718bfeeab8f60d8ae12b31bbcbb89 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 3 May 2022 22:03:43 -0500 Subject: [PATCH] ports: Rename thread_t to mp_thread_t. This adds the `mp_` prefix to the `thread_t` type. The name `thread_t` conflicts with the same in `mach/mach_types.h` on macOS. Signed-off-by: David Lechner --- ports/cc3200/mpthreadport.c | 18 +++++++++--------- ports/esp32/mpthreadport.c | 24 ++++++++++++------------ ports/unix/mpthreadport.c | 22 +++++++++++----------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/ports/cc3200/mpthreadport.c b/ports/cc3200/mpthreadport.c index d35dab2d15..4b6f27d578 100644 --- a/ports/cc3200/mpthreadport.c +++ b/ports/cc3200/mpthreadport.c @@ -37,19 +37,19 @@ #if MICROPY_PY_THREAD // this structure forms a linked list, one node per active thread -typedef struct _thread_t { +typedef struct _mp_thread_t { TaskHandle_t id; // system id of thread int ready; // whether the thread is ready and running void *arg; // thread Python args, a GC root pointer void *stack; // pointer to the stack size_t stack_len; // number of words in the stack - struct _thread_t *next; -} thread_t; + struct _mp_thread_t *next; +} mp_thread_t; // the mutex controls access to the linked list STATIC mp_thread_mutex_t thread_mutex; -STATIC thread_t thread_entry0; -STATIC thread_t *thread; // root pointer, handled bp mp_thread_gc_others +STATIC mp_thread_t thread_entry0; +STATIC mp_thread_t *thread; // root pointer, handled bp mp_thread_gc_others void mp_thread_init(void) { mp_thread_mutex_init(&thread_mutex); @@ -67,7 +67,7 @@ void mp_thread_init(void) { void mp_thread_gc_others(void) { mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { gc_collect_root((void **)&th, 1); gc_collect_root(&th->arg, 1); // probably not needed if (th->id == xTaskGetCurrentTaskHandle()) { @@ -91,7 +91,7 @@ void mp_thread_set_state(mp_state_thread_t *state) { void mp_thread_start(void) { mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { if (th->id == xTaskGetCurrentTaskHandle()) { th->ready = 1; break; @@ -124,7 +124,7 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) { // allocate TCB, stack and linked-list node (must be outside thread_mutex lock) StaticTask_t *tcb = m_new(StaticTask_t, 1); StackType_t *stack = m_new(StackType_t, *stack_size / sizeof(StackType_t)); - thread_t *th = m_new_obj(thread_t); + mp_thread_t *th = m_new_obj(mp_thread_t); mp_thread_mutex_lock(&thread_mutex, 1); @@ -153,7 +153,7 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) { void mp_thread_finish(void) { mp_thread_mutex_lock(&thread_mutex, 1); // TODO unlink from list - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { if (th->id == xTaskGetCurrentTaskHandle()) { th->ready = 0; break; diff --git a/ports/esp32/mpthreadport.c b/ports/esp32/mpthreadport.c index 9d1c4a758c..e6c7e9bc80 100644 --- a/ports/esp32/mpthreadport.c +++ b/ports/esp32/mpthreadport.c @@ -42,19 +42,19 @@ #define MP_THREAD_PRIORITY (ESP_TASK_PRIO_MIN + 1) // this structure forms a linked list, one node per active thread -typedef struct _thread_t { +typedef struct _mp_thread_t { TaskHandle_t id; // system id of thread int ready; // whether the thread is ready and running void *arg; // thread Python args, a GC root pointer void *stack; // pointer to the stack size_t stack_len; // number of words in the stack - struct _thread_t *next; -} thread_t; + struct _mp_thread_t *next; +} mp_thread_t; // the mutex controls access to the linked list STATIC mp_thread_mutex_t thread_mutex; -STATIC thread_t thread_entry0; -STATIC thread_t *thread = NULL; // root pointer, handled by mp_thread_gc_others +STATIC mp_thread_t thread_entry0; +STATIC mp_thread_t *thread = NULL; // root pointer, handled by mp_thread_gc_others void mp_thread_init(void *stack, uint32_t stack_len) { mp_thread_set_state(&mp_state_ctx.thread); @@ -76,7 +76,7 @@ void mp_thread_init(void *stack, uint32_t stack_len) { void mp_thread_gc_others(void) { mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { gc_collect_root((void **)&th, 1); gc_collect_root(&th->arg, 1); // probably not needed if (th->id == xTaskGetCurrentTaskHandle()) { @@ -100,7 +100,7 @@ void mp_thread_set_state(mp_state_thread_t *state) { void mp_thread_start(void) { mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { if (th->id == xTaskGetCurrentTaskHandle()) { th->ready = 1; break; @@ -131,7 +131,7 @@ void mp_thread_create_ex(void *(*entry)(void *), void *arg, size_t *stack_size, } // Allocate linked-list node (must be outside thread_mutex lock) - thread_t *th = m_new_obj(thread_t); + mp_thread_t *th = m_new_obj(mp_thread_t); mp_thread_mutex_lock(&thread_mutex, 1); @@ -162,7 +162,7 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) { void mp_thread_finish(void) { mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { if (th->id == xTaskGetCurrentTaskHandle()) { th->ready = 0; break; @@ -178,9 +178,9 @@ void vPortCleanUpTCB(void *tcb) { // threading not yet initialised return; } - thread_t *prev = NULL; + mp_thread_t *prev = NULL; mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; prev = th, th = th->next) { + for (mp_thread_t *th = thread; th != NULL; prev = th, th = th->next) { // unlink the node from the list if ((void *)th->id == tcb) { if (prev != NULL) { @@ -216,7 +216,7 @@ void mp_thread_deinit(void) { // Find a task to delete TaskHandle_t id = NULL; mp_thread_mutex_lock(&thread_mutex, 1); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { // Don't delete the current task if (th->id != xTaskGetCurrentTaskHandle()) { id = th->id; diff --git a/ports/unix/mpthreadport.c b/ports/unix/mpthreadport.c index 63aac1da38..2ec7e65d3b 100644 --- a/ports/unix/mpthreadport.c +++ b/ports/unix/mpthreadport.c @@ -53,12 +53,12 @@ #define THREAD_STACK_OVERFLOW_MARGIN (8192) // this structure forms a linked list, one node per active thread -typedef struct _thread_t { +typedef struct _mp_thread_t { pthread_t id; // system id of thread int ready; // whether the thread is ready and running void *arg; // thread Python args, a GC root pointer - struct _thread_t *next; -} thread_t; + struct _mp_thread_t *next; +} mp_thread_t; STATIC pthread_key_t tls_key; @@ -66,7 +66,7 @@ STATIC pthread_key_t tls_key; // Specifically for thread management, access to the linked list is one example. // But also, e.g. scheduler state. STATIC pthread_mutex_t thread_mutex; -STATIC thread_t *thread; +STATIC mp_thread_t *thread; // this is used to synchronise the signal handler of the thread // it's needed because we can't use any pthread calls in a signal handler @@ -119,7 +119,7 @@ void mp_thread_init(void) { pthread_mutex_init(&thread_mutex, &thread_mutex_attr); // create first entry in linked list of all threads - thread = malloc(sizeof(thread_t)); + thread = malloc(sizeof(mp_thread_t)); thread->id = pthread_self(); thread->ready = 1; thread->arg = NULL; @@ -143,7 +143,7 @@ void mp_thread_init(void) { void mp_thread_deinit(void) { mp_thread_unix_begin_atomic_section(); while (thread->next != NULL) { - thread_t *th = thread; + mp_thread_t *th = thread; thread = thread->next; pthread_cancel(th->id); free(th); @@ -165,7 +165,7 @@ void mp_thread_deinit(void) { // garbage collection and tracing these pointers. void mp_thread_gc_others(void) { mp_thread_unix_begin_atomic_section(); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { gc_collect_root(&th->arg, 1); if (th->id == pthread_self()) { continue; @@ -194,7 +194,7 @@ void mp_thread_set_state(mp_state_thread_t *state) { void mp_thread_start(void) { pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); mp_thread_unix_begin_atomic_section(); - for (thread_t *th = thread; th != NULL; th = th->next) { + for (mp_thread_t *th = thread; th != NULL; th = th->next) { if (th->id == pthread_self()) { th->ready = 1; break; @@ -249,7 +249,7 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) { *stack_size -= THREAD_STACK_OVERFLOW_MARGIN; // add thread to linked list of all threads - thread_t *th = malloc(sizeof(thread_t)); + mp_thread_t *th = malloc(sizeof(mp_thread_t)); th->id = id; th->ready = 0; th->arg = arg; @@ -266,8 +266,8 @@ er: void mp_thread_finish(void) { mp_thread_unix_begin_atomic_section(); - thread_t *prev = NULL; - for (thread_t *th = thread; th != NULL; th = th->next) { + mp_thread_t *prev = NULL; + for (mp_thread_t *th = thread; th != NULL; th = th->next) { if (th->id == pthread_self()) { if (prev == NULL) { thread = th->next;