-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
__errno_location
under wasm workers. NFC (#22744)
Previously the wasm workers build of `__errno_location` was using the single threaded code path which doesn't use a thead local location. In addition this change avoids the use of `__EMSCRIPTEN_PTHREADS__` in `__errno_location.c` which is helpful for unifying the shared memory libc build. See #22735.
- Loading branch information
Showing
3 changed files
with
21 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
#include <errno.h> | ||
#include "pthread_impl.h" | ||
|
||
#if __EMSCRIPTEN_PTHREADS__ | ||
// for pthreads, use the proper location on the thread info, so each | ||
// thread has its own errno | ||
int *__errno_location(void) | ||
{ | ||
return &__pthread_self()->errno_val; | ||
} | ||
#else | ||
// for single-threaded mode, avoid linking in pthreads support code | ||
// just for this | ||
static int __errno_storage = 0; | ||
#if __EMSCRIPTEN__ | ||
// For emscripten we use TLS here instead of `__pthread_self`, so that in single | ||
// threaded builds this gets lowered away to normal global variable. | ||
static _Thread_local int __errno_storage = 0; | ||
#endif | ||
|
||
int *__errno_location(void) | ||
{ | ||
#if __EMSCRIPTEN__ | ||
return &__errno_storage; | ||
} | ||
#else | ||
return &__pthread_self()->errno_val; | ||
#endif | ||
} | ||
|
||
weak_alias(__errno_location, ___errno_location); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters