Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/struct_info_internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"_a_transferredcanvases"
],
"thread_profiler_block": [
"threadStatus",
"timeSpentInStatus",
"name"
"threadStatus",
"timeSpentInStatus",
"name"
]
}
},
Expand Down
6 changes: 2 additions & 4 deletions system/lib/libc/musl/src/thread/__timedwait.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
#include <time.h>
#include <errno.h>
#ifdef __EMSCRIPTEN__
#include <math.h>
#include <emscripten/threading.h>
#include <emscripten/emscripten.h>
#include <math.h> // for INFINITY
#else
#include "futex.h"
#endif
#include "syscall.h"
#endif
#include "pthread_impl.h"

#ifndef __EMSCRIPTEN__
Expand Down
3 changes: 1 addition & 2 deletions system/lib/libc/musl/src/thread/__wait.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifdef __EMSCRIPTEN__
#include <math.h>
#include <emscripten/threading.h>
#include <math.h> // for INFINITY
#endif

#include "pthread_impl.h"
Expand Down
4 changes: 2 additions & 2 deletions system/lib/libc/musl/src/thread/pthread_barrier_wait.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef __EMSCRIPTEN__
#include <assert.h> // For INFINITY
#include <math.h> // For INFINITY
#include <assert.h> // for assert
#include <math.h> // for INFINITY
#endif

#include "pthread_impl.h"
Expand Down
3 changes: 2 additions & 1 deletion system/lib/libc/musl/src/thread/pthread_detach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions system/lib/libc/musl/src/thread/pthread_key_create.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "pthread_impl.h"
#include "fork_impl.h"

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 };

Expand Down
2 changes: 0 additions & 2 deletions system/lib/libc/musl/src/thread/thrd_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 3 additions & 16 deletions system/lib/pthread/library_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <termios.h>
#include <threads.h>
#include <unistd.h>
#include <utime.h>

#include <emscripten.h>
#include <emscripten/proxying.h>
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions system/lib/pthread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* found in the LICENSE file.
*/

#define _GNU_SOURCE
#include "pthread_impl.h"
#include "stdio_impl.h"
#include "assert.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion system/lib/pthread/threading_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/pthread/main_thread_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading