Skip to content

Commit c7ef7db

Browse files
authored
Simplify timezone setup. NFC (#26377)
The code here previously used a pthread_lock. However this is unnecessary since all calls to the `do_tzset` function are already wrapped in `LOCK(lock)` and `UNLOCK(lock)`. This is nice little codesize saving too.
1 parent c239ade commit c7ef7db

10 files changed

+39
-51
lines changed

system/lib/libc/musl/src/time/__tz.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99
#include "lock.h"
1010
#include "fork_impl.h"
1111

12-
#ifdef __EMSCRIPTEN__
13-
#include <stdbool.h>
14-
#include <pthread.h>
15-
#include "emscripten_internal.h"
16-
#endif
17-
1812
#if defined(__EMSCRIPTEN__) && !defined(EMSCRIPTEN_STANDALONE_WASM)
1913
#define USE_EXTERNAL_ZONEINFO
14+
#include "emscripten_internal.h"
2015
#endif
2116

2217
#define malloc __libc_malloc
@@ -142,17 +137,10 @@ static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t
142137
static void do_tzset()
143138
{
144139
#ifdef USE_EXTERNAL_ZONEINFO
145-
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
146-
static _Atomic bool done_init = false;
147-
if (!done_init) {
148-
pthread_mutex_lock(&lock);
149-
if (!done_init) {
150-
_tzset_js(&timezone, &daylight, std_name, dst_name);
151-
__tzname[0] = std_name;
152-
__tzname[1] = dst_name;
153-
done_init = true;
154-
}
155-
pthread_mutex_unlock(&lock);
140+
if (!__tzname[0]) {
141+
_tzset_js(&timezone, &daylight, std_name, dst_name);
142+
__tzname[0] = std_name;
143+
__tzname[1] = dst_name;
156144
}
157145
#else
158146
char buf[NAME_MAX+25], *pathname=buf+24;

test/codesize/test_codesize_cxx_ctors1.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19555,
33
"a.out.js.gz": 8102,
4-
"a.out.nodebug.wasm": 132828,
5-
"a.out.nodebug.wasm.gz": 49876,
6-
"total": 152383,
7-
"total_gz": 57978,
4+
"a.out.nodebug.wasm": 132802,
5+
"a.out.nodebug.wasm.gz": 49860,
6+
"total": 152357,
7+
"total_gz": 57962,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_ctors2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19532,
33
"a.out.js.gz": 8087,
4-
"a.out.nodebug.wasm": 132248,
5-
"a.out.nodebug.wasm.gz": 49533,
6-
"total": 151780,
7-
"total_gz": 57620,
4+
"a.out.nodebug.wasm": 132222,
5+
"a.out.nodebug.wasm.gz": 49513,
6+
"total": 151754,
7+
"total_gz": 57600,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_except.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 23216,
33
"a.out.js.gz": 9081,
4-
"a.out.nodebug.wasm": 172758,
5-
"a.out.nodebug.wasm.gz": 57391,
6-
"total": 195974,
7-
"total_gz": 66472,
4+
"a.out.nodebug.wasm": 172732,
5+
"a.out.nodebug.wasm.gz": 57374,
6+
"total": 195948,
7+
"total_gz": 66455,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/codesize/test_codesize_cxx_except_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19366,
33
"a.out.js.gz": 8022,
4-
"a.out.nodebug.wasm": 148153,
5-
"a.out.nodebug.wasm.gz": 55273,
6-
"total": 167519,
7-
"total_gz": 63295,
4+
"a.out.nodebug.wasm": 148127,
5+
"a.out.nodebug.wasm.gz": 55257,
6+
"total": 167493,
7+
"total_gz": 63279,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/codesize/test_codesize_cxx_except_wasm_legacy.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19440,
33
"a.out.js.gz": 8042,
4-
"a.out.nodebug.wasm": 145959,
5-
"a.out.nodebug.wasm.gz": 54905,
6-
"total": 165399,
7-
"total_gz": 62947,
4+
"a.out.nodebug.wasm": 145933,
5+
"a.out.nodebug.wasm.gz": 54885,
6+
"total": 165373,
7+
"total_gz": 62927,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/codesize/test_codesize_cxx_mangle.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 23266,
33
"a.out.js.gz": 9101,
4-
"a.out.nodebug.wasm": 239192,
5-
"a.out.nodebug.wasm.gz": 79786,
6-
"total": 262458,
7-
"total_gz": 88887,
4+
"a.out.nodebug.wasm": 239166,
5+
"a.out.nodebug.wasm.gz": 79776,
6+
"total": 262432,
7+
"total_gz": 88877,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/codesize/test_codesize_cxx_noexcept.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19555,
33
"a.out.js.gz": 8102,
4-
"a.out.nodebug.wasm": 134835,
5-
"a.out.nodebug.wasm.gz": 50703,
6-
"total": 154390,
7-
"total_gz": 58805,
4+
"a.out.nodebug.wasm": 134809,
5+
"a.out.nodebug.wasm.gz": 50697,
6+
"total": 154364,
7+
"total_gz": 58799,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_wasmfs.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7053,
33
"a.out.js.gz": 3325,
4-
"a.out.nodebug.wasm": 172904,
5-
"a.out.nodebug.wasm.gz": 63290,
6-
"total": 179957,
7-
"total_gz": 66615,
4+
"a.out.nodebug.wasm": 172878,
5+
"a.out.nodebug.wasm.gz": 63283,
6+
"total": 179931,
7+
"total_gz": 66608,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"a.out.js": 244691,
3-
"a.out.nodebug.wasm": 577708,
4-
"total": 822399,
3+
"a.out.nodebug.wasm": 577692,
4+
"total": 822383,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)