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
10 changes: 5 additions & 5 deletions src/struct_info_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,11 @@
"p_proto": 8
},
"pthread": {
"__size__": 132,
"profilerBlock": 112,
"stack": 52,
"stack_size": 56,
"waiting_async": 128
"__size__": 124,
"profilerBlock": 104,
"stack": 48,
"stack_size": 52,
"waiting_async": 120
},
"pthread_attr_t": {
"__size__": 44,
Expand Down
10 changes: 5 additions & 5 deletions src/struct_info_generated_wasm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,11 @@
"p_proto": 16
},
"pthread": {
"__size__": 232,
"profilerBlock": 200,
"stack": 88,
"stack_size": 96,
"waiting_async": 228
"__size__": 216,
"profilerBlock": 184,
"stack": 80,
"stack_size": 88,
"waiting_async": 212
},
"pthread_attr_t": {
"__size__": 88,
Expand Down
8 changes: 8 additions & 0 deletions system/lib/libc/musl/src/internal/locale_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ hidden char *__gettextdomain(void);
#define C_LOCALE ((locale_t)&__c_locale)
#define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale)

#ifdef __EMSCRIPTEN__
extern _Thread_local locale_t __tls_locale;

#define CURRENT_LOCALE (__tls_locale)

#define CURRENT_UTF8 (!!__tls_locale->cat[LC_CTYPE])
#else
#define CURRENT_LOCALE (__pthread_self()->locale)

#define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE])
#endif

#undef MB_CUR_MAX
#define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1)
Expand Down
6 changes: 6 additions & 0 deletions system/lib/libc/musl/src/internal/pthread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ struct pthread {

/* Part 2 -- implementation details, non-ABI. */
int tid;
#ifndef __EMSCRIPTEN__
// Emscripten uses C11 _Thread_local instead for errno
int errno_val;
#endif
volatile int detach_state;
volatile int cancel;
volatile unsigned char canceldisable, cancelasync;
Expand All @@ -60,7 +63,10 @@ struct pthread {
} robust_list;
int h_errno_val;
volatile int timer_id;
#ifndef __EMSCRIPTEN__
// Emscripten uses C11 _Thread_local instead for locale
locale_t locale;
#endif
volatile int killlock[1];
char *dlerror_buf;
void *stdio_locks;
Expand Down
11 changes: 11 additions & 0 deletions system/lib/libc/musl/src/locale/uselocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
#include "pthread_impl.h"
#include "libc.h"

#ifdef __EMSCRIPTEN__
_Thread_local locale_t __tls_locale = &libc.global_locale;
#endif

locale_t __uselocale(locale_t new)
{
#ifdef __EMSCRIPTEN__
locale_t old = __tls_locale;
locale_t global = &libc.global_locale;

if (new) __tls_locale = new == LC_GLOBAL_LOCALE ? global : new;
#else
pthread_t self = __pthread_self();
locale_t old = self->locale;
locale_t global = &libc.global_locale;

if (new) self->locale = new == LC_GLOBAL_LOCALE ? global : new;
#endif

return old == global ? LC_GLOBAL_LOCALE : old;
}
Expand Down
1 change: 0 additions & 1 deletion system/lib/pthread/library_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ void _emscripten_init_main_thread(void) {
// Main thread ID is always 1. It can't be 0 because musl assumes
// tid is always non-zero.
__main_pthread.tid = getpid();
__main_pthread.locale = &libc.global_locale;
// 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;
Expand Down
1 change: 0 additions & 1 deletion system/lib/pthread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ int __pthread_create(pthread_t* restrict res,
// pthread struct robust_list head should point to itself.
new->robust_list.head = &new->robust_list.head;

new->locale = &libc.global_locale;
if (attr._a_detach) {
new->detach_state = DT_DETACHED;
} else {
Expand Down
1 change: 0 additions & 1 deletion system/lib/pthread/pthread_self_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ extern int __stack_low;

__attribute__((constructor))
static void init_pthread_self(void) {
__main_pthread.locale = &libc.global_locale;
__main_pthread.tid = getpid();
__main_pthread.stack = &__stack_high;
__main_pthread.stack_size = ((size_t)&__stack_high) - ((size_t)&__stack_low);
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19214,
"a.out.js.gz": 7981,
"a.out.nodebug.wasm": 132658,
"a.out.nodebug.wasm.gz": 49938,
"total": 151872,
"total_gz": 57919,
"a.out.nodebug.wasm": 132638,
"a.out.nodebug.wasm.gz": 49927,
"total": 151852,
"total_gz": 57908,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19191,
"a.out.js.gz": 7966,
"a.out.nodebug.wasm": 132082,
"a.out.nodebug.wasm.gz": 49598,
"total": 151273,
"total_gz": 57564,
"a.out.nodebug.wasm": 132064,
"a.out.nodebug.wasm.gz": 49586,
"total": 151255,
"total_gz": 57552,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22875,
"a.out.js.gz": 8956,
"a.out.nodebug.wasm": 172547,
"a.out.nodebug.wasm.gz": 57453,
"total": 195422,
"total_gz": 66409,
"a.out.nodebug.wasm": 172540,
"a.out.nodebug.wasm.gz": 57452,
"total": 195415,
"total_gz": 66408,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19025,
"a.out.js.gz": 7908,
"a.out.nodebug.wasm": 147940,
"a.out.nodebug.wasm.gz": 55311,
"total": 166965,
"total_gz": 63219,
"a.out.nodebug.wasm": 147922,
"a.out.nodebug.wasm.gz": 55312,
"total": 166947,
"total_gz": 63220,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm_legacy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19099,
"a.out.js.gz": 7930,
"a.out.nodebug.wasm": 145746,
"a.out.nodebug.wasm.gz": 54944,
"total": 164845,
"total_gz": 62874,
"a.out.nodebug.wasm": 145729,
"a.out.nodebug.wasm.gz": 54945,
"total": 164828,
"total_gz": 62875,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_lto.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18562,
"a.out.js.gz": 7668,
"a.out.nodebug.wasm": 101965,
"a.out.nodebug.wasm.gz": 39470,
"total": 120527,
"total_gz": 47138,
"a.out.nodebug.wasm": 101956,
"a.out.nodebug.wasm.gz": 39461,
"total": 120518,
"total_gz": 47129,
"sent": [
"a (emscripten_resize_heap)",
"b (_setitimer_js)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22925,
"a.out.js.gz": 8978,
"a.out.nodebug.wasm": 238988,
"a.out.nodebug.wasm.gz": 79856,
"total": 261913,
"total_gz": 88834,
"a.out.nodebug.wasm": 238981,
"a.out.nodebug.wasm.gz": 79855,
"total": 261906,
"total_gz": 88833,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_noexcept.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19214,
"a.out.js.gz": 7981,
"a.out.nodebug.wasm": 134678,
"a.out.nodebug.wasm.gz": 50780,
"total": 153892,
"total_gz": 58761,
"a.out.nodebug.wasm": 134661,
"a.out.nodebug.wasm.gz": 50777,
"total": 153875,
"total_gz": 58758,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_wasmfs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7053,
"a.out.js.gz": 3325,
"a.out.nodebug.wasm": 172754,
"a.out.nodebug.wasm.gz": 63338,
"total": 179807,
"total_gz": 66663,
"a.out.nodebug.wasm": 172736,
"a.out.nodebug.wasm.gz": 63329,
"total": 179789,
"total_gz": 66654,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
14 changes: 5 additions & 9 deletions test/codesize/test_codesize_hello_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 24271,
"a.out.js.gz": 8729,
"a.out.nodebug.wasm": 14973,
"a.out.nodebug.wasm.gz": 7397,
"total": 39244,
"total_gz": 16126,
"a.out.js.gz": 8724,
"a.out.nodebug.wasm": 14850,
"a.out.nodebug.wasm.gz": 7311,
"total": 39121,
"total_gz": 16035,
"sent": [
"fd_write"
],
Expand Down Expand Up @@ -33,7 +33,6 @@
"$__emscripten_stdout_seek",
"$__errno_location",
"$__fwritex",
"$__get_tp",
"$__lock",
"$__lshrti3",
"$__memcpy",
Expand All @@ -43,7 +42,6 @@
"$__original_main",
"$__stdio_write",
"$__strerror_l",
"$__syscall_getpid",
"$__towrite",
"$__trunctfdf2",
"$__unlock",
Expand All @@ -65,8 +63,6 @@
"$fmt_x",
"$frexp",
"$getint",
"$getpid",
"$init_pthread_self",
"$main",
"$memchr",
"$out",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_dylink.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 26256,
"a.out.js.gz": 11230,
"a.out.nodebug.wasm": 17675,
"a.out.nodebug.wasm.gz": 8932,
"total": 43931,
"total_gz": 20162,
"a.out.nodebug.wasm": 17670,
"a.out.nodebug.wasm.gz": 8926,
"total": 43926,
"total_gz": 20156,
"sent": [
"__syscall_stat64",
"emscripten_resize_heap",
Expand Down
5 changes: 3 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 244367,
"a.out.nodebug.wasm": 577300,
"total": 821667,
"a.out.nodebug.wasm": 577323,
"total": 821690,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down Expand Up @@ -1908,6 +1908,7 @@
"__sysv_signal",
"__threwValue",
"__timezone",
"__tls_locale",
"__tolower_l",
"__toupper_l",
"__towctrans_l",
Expand Down
10 changes: 5 additions & 5 deletions test/codesize/test_codesize_minimal_pthreads.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7884,
"a.out.js.gz": 3854,
"a.out.nodebug.wasm": 19726,
"a.out.nodebug.wasm.gz": 9135,
"total": 27610,
"total_gz": 12989,
"a.out.js.gz": 3855,
"a.out.nodebug.wasm": 19707,
"a.out.nodebug.wasm.gz": 9122,
"total": 27591,
"total_gz": 12977,
"sent": [
"a (memory)",
"b (emscripten_get_now)",
Expand Down
10 changes: 5 additions & 5 deletions test/codesize/test_codesize_minimal_pthreads_memgrowth.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 8306,
"a.out.js.gz": 4059,
"a.out.nodebug.wasm": 19727,
"a.out.nodebug.wasm.gz": 9137,
"total": 28033,
"total_gz": 13196,
"a.out.js.gz": 4060,
"a.out.nodebug.wasm": 19708,
"a.out.nodebug.wasm.gz": 9123,
"total": 28014,
"total_gz": 13183,
"sent": [
"a (memory)",
"b (emscripten_get_now)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 371,
"a.js": 5353,
"a.js.gz": 2524,
"a.wasm": 5806,
"a.wasm.gz": 2737,
"total": 11707,
"total_gz": 5632
"a.wasm": 5797,
"a.wasm.gz": 2732,
"total": 11698,
"total_gz": 5627
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"a.html": 10873,
"a.html.gz": 5681
"a.html": 10815,
"a.html.gz": 5649
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"a.html": 17175,
"a.html.gz": 7509
"a.html": 17114,
"a.html.gz": 7478
}
Loading
Loading