diff --git a/src/struct_info_internal.json b/src/struct_info_internal.json index 4681b77fe55a0..de28e7a0b6c4c 100644 --- a/src/struct_info_internal.json +++ b/src/struct_info_internal.json @@ -15,9 +15,9 @@ "_a_transferredcanvases" ], "thread_profiler_block": [ - "threadStatus", - "timeSpentInStatus", - "name" + "threadStatus", + "timeSpentInStatus", + "name" ] } }, diff --git a/system/lib/libc/musl/src/thread/__timedwait.c b/system/lib/libc/musl/src/thread/__timedwait.c index 9e3ccc9849257..2c82d2ab1e8c0 100644 --- a/system/lib/libc/musl/src/thread/__timedwait.c +++ b/system/lib/libc/musl/src/thread/__timedwait.c @@ -2,13 +2,11 @@ #include #include #ifdef __EMSCRIPTEN__ -#include -#include -#include +#include // for INFINITY #else #include "futex.h" -#endif #include "syscall.h" +#endif #include "pthread_impl.h" #ifndef __EMSCRIPTEN__ diff --git a/system/lib/libc/musl/src/thread/__wait.c b/system/lib/libc/musl/src/thread/__wait.c index 66a140bd69401..fe3b5cf38b071 100644 --- a/system/lib/libc/musl/src/thread/__wait.c +++ b/system/lib/libc/musl/src/thread/__wait.c @@ -1,6 +1,5 @@ #ifdef __EMSCRIPTEN__ -#include -#include +#include // for INFINITY #endif #include "pthread_impl.h" diff --git a/system/lib/libc/musl/src/thread/pthread_barrier_wait.c b/system/lib/libc/musl/src/thread/pthread_barrier_wait.c index 37aebd0f1de3f..37180c8e5a8ad 100644 --- a/system/lib/libc/musl/src/thread/pthread_barrier_wait.c +++ b/system/lib/libc/musl/src/thread/pthread_barrier_wait.c @@ -1,6 +1,6 @@ #ifdef __EMSCRIPTEN__ -#include // For INFINITY -#include // For INFINITY +#include // for assert +#include // for INFINITY #endif #include "pthread_impl.h" diff --git a/system/lib/libc/musl/src/thread/pthread_detach.c b/system/lib/libc/musl/src/thread/pthread_detach.c index c25882cca4ac1..2b516e232db06 100644 --- a/system/lib/libc/musl/src/thread/pthread_detach.c +++ b/system/lib/libc/musl/src/thread/pthread_detach.c @@ -32,5 +32,6 @@ static int __pthread_detach(pthread_t t) weak_alias(__pthread_detach, pthread_detach); weak_alias(__pthread_detach, thrd_detach); -// XXX EMSCRIPTEN: add extra alias for asan. +#ifdef __EMSCRIPTEN__ // XXX Emscripten add an extra alias for ASan/LSan. weak_alias(__pthread_detach, emscripten_builtin_pthread_detach); +#endif diff --git a/system/lib/libc/musl/src/thread/pthread_key_create.c b/system/lib/libc/musl/src/thread/pthread_key_create.c index f45553919647a..39770c7a3c829 100644 --- a/system/lib/libc/musl/src/thread/pthread_key_create.c +++ b/system/lib/libc/musl/src/thread/pthread_key_create.c @@ -1,10 +1,6 @@ #include "pthread_impl.h" #include "fork_impl.h" -#ifdef __EMSCRIPTEN__ -#include -#endif - volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; diff --git a/system/lib/libc/musl/src/thread/thrd_create.c b/system/lib/libc/musl/src/thread/thrd_create.c index ca4efb661973b..d1191660a292d 100644 --- a/system/lib/libc/musl/src/thread/thrd_create.c +++ b/system/lib/libc/musl/src/thread/thrd_create.c @@ -6,8 +6,6 @@ // if we call the internal __pthread_create function here to don't the wrapping // See pthread_create wrapper in compiler-rt/lib/lsan/lsan_interceptors.cpp. #define __pthread_create pthread_create -#else -int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict); #endif int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) diff --git a/system/lib/pthread/library_pthread.c b/system/lib/pthread/library_pthread.c index 0a47e1a4dd863..b8a48cb91f1c9 100644 --- a/system/lib/pthread/library_pthread.c +++ b/system/lib/pthread/library_pthread.c @@ -5,27 +5,13 @@ * found in the LICENSE file. */ -#define _GNU_SOURCE -#include "../internal/libc.h" -#include "../internal/pthread_impl.h" +#include "libc.h" +#include "pthread_impl.h" #include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include #include #include @@ -136,6 +122,7 @@ void _emscripten_init_main_thread(void) { // pthread struct prev and next should initially point to itself (see __init_tp), // this is used by pthread_key_delete for deleting thread-specific data. __main_pthread.next = __main_pthread.prev = &__main_pthread; + // Initialize thread-specific data area. __main_pthread.tsd = (void **)__pthread_tsd_main; _emscripten_init_main_thread_js(&__main_pthread); diff --git a/system/lib/pthread/pthread_create.c b/system/lib/pthread/pthread_create.c index 00df6ad4b8854..5fe3d9bdd90f7 100644 --- a/system/lib/pthread/pthread_create.c +++ b/system/lib/pthread/pthread_create.c @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#define _GNU_SOURCE #include "pthread_impl.h" #include "stdio_impl.h" #include "assert.h" @@ -108,7 +107,7 @@ int __pthread_create(pthread_t* restrict res, void* (*entry)(void*), void* restrict arg) { // Note on LSAN: lsan intercepts/wraps calls to pthread_create so any - // allocation we do here should be considered leaks. + // allocations we do here should not be considered leaks. // See: lsan_interceptors.cpp. if (!res) { return EINVAL; @@ -292,10 +291,10 @@ void _emscripten_thread_free_data(pthread_t t) { } void _emscripten_thread_exit(void* result) { - struct pthread *self = __pthread_self(); + pthread_t self = __pthread_self(); assert(self); - self->canceldisable = PTHREAD_CANCEL_DISABLE; + self->canceldisable = 1; self->cancelasync = 0; self->result = result; @@ -344,8 +343,8 @@ void _emscripten_thread_exit(void* result) { // Not hosting a pthread anymore in this worker set __pthread_self to NULL __set_thread_state(NULL, 0, 0, 1); - /* This atomic potentially competes with a concurrent pthread_detach - * call; the loser is responsible for freeing thread resources. */ + // This atomic potentially competes with a concurrent pthread_detach + // call; the loser is responsible for freeing thread resources. int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING); if (state == DT_DETACHED) { @@ -363,7 +362,7 @@ void _emscripten_thread_exit(void* result) { } } -// Mark as `no_sanitize("address"` since emscripten_pthread_exit destroys +// Mark as `no_sanitize("address")` since emscripten_pthread_exit destroys // the current thread and runs its exit handlers. Without this asan injects // a call to __asan_handle_no_return before emscripten_unwind_to_js_event_loop // which seem to cause a crash later down the line. diff --git a/system/lib/pthread/threading_internal.h b/system/lib/pthread/threading_internal.h index b4474dea206d2..7803603ccedfa 100644 --- a/system/lib/pthread/threading_internal.h +++ b/system/lib/pthread/threading_internal.h @@ -105,7 +105,7 @@ void emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS expectedS #endif int __pthread_kill_js(pthread_t t, int sig); -int __pthread_create_js(struct __pthread *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); +int __pthread_create_js(pthread_t thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); int _emscripten_default_pthread_stack_size(); void __set_thread_state(pthread_t ptr, int is_main, int is_runtime, int can_block); diff --git a/test/pthread/main_thread_join.cpp b/test/pthread/main_thread_join.cpp index afa611aaf7ad5..ece9c74d59920 100644 --- a/test/pthread/main_thread_join.cpp +++ b/test/pthread/main_thread_join.cpp @@ -33,7 +33,7 @@ void *ThreadMain(void *arg) { // succeeding. while (tries.load() < EXPECTED_TRIES) {} #endif - pthread_exit((void*)0); + pthread_exit((void*)0); } pthread_t CreateThread() {