-
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.
Avoid use of __EMSCRIPTEN_PTHREADS__ in __errno_location.c
Instead we can use TLS which works for both single and multithreaded builds and also works with wasm workers. This is also needed for #22735
- Loading branch information
Showing
3 changed files
with
14 additions
and
17 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 get 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