6
6
7
7
var LibraryPThread = {
8
8
$PThread__postset : 'if (!ENVIRONMENT_IS_PTHREAD) PThread.initMainThreadBlock();' ,
9
- $PThread__deps : [ '$registerPthreadPtr ' ,
9
+ $PThread__deps : [ '_emscripten_thread_init ' ,
10
10
'$ERRNO_CODES' , 'emscripten_futex_wake' , '$killThread' ,
11
11
'$cancelThread' , '$cleanupThread' ,
12
12
#if USE_ASAN || USE_LSAN
@@ -86,10 +86,10 @@ var LibraryPThread = {
86
86
} ) ;
87
87
#endif
88
88
89
- // Pass the thread address inside the asm.js scope to store it for fast
90
- // access that avoids the need for a FFI out. Global constructors trying
89
+ // Pass the thread address to the native code where they stored in wasm
90
+ // globals which act as a form of TLS. Global constructors trying
91
91
// to access this value will read the wrong value, but that is UB anyway.
92
- registerPthreadPtr ( PThread . mainThreadBlock , /*isMainBrowserThread=*/ ! ENVIRONMENT_IS_WORKER , /*isMainRuntimeThread=*/ 1 ) ;
92
+ __emscripten_thread_init ( PThread . mainThreadBlock , /*isMainBrowserThread=*/ ! ENVIRONMENT_IS_WORKER , /*isMainRuntimeThread=*/ 1 ) ;
93
93
_emscripten_register_main_browser_thread_id ( PThread . mainThreadBlock ) ;
94
94
} ,
95
95
initWorker: function ( ) {
@@ -223,7 +223,7 @@ var LibraryPThread = {
223
223
PThread . runExitHandlers ( ) ;
224
224
225
225
_emscripten_futex_wake ( tb + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ;
226
- registerPthreadPtr ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
226
+ __emscripten_thread_init ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
227
227
threadInfoStruct = 0 ;
228
228
if ( ENVIRONMENT_IS_PTHREAD ) {
229
229
// Note: in theory we would like to return any offscreen canvases back to the main thread,
@@ -239,7 +239,7 @@ var LibraryPThread = {
239
239
Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . threadStatus } } } ) >> 2 , 1 ) ; // Mark the thread as no longer running.
240
240
_emscripten_futex_wake ( threadInfoStruct + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ; // wake all threads
241
241
threadInfoStruct = selfThreadId = 0 ; // Not hosting a pthread anymore in this worker, reset the info structures to null.
242
- registerPthreadPtr ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
242
+ __emscripten_thread_init ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
243
243
postMessage ( { 'cmd' : 'cancelDone' } ) ;
244
244
} ,
245
245
@@ -1010,46 +1010,9 @@ var LibraryPThread = {
1010
1010
throw 'unwind' ;
1011
1011
} ,
1012
1012
1013
- _pthread_ptr : 0 ,
1014
1013
_pthread_is_main_runtime_thread : 0 ,
1015
1014
_pthread_is_main_browser_thread : 0 ,
1016
1015
1017
- $registerPthreadPtr__deps : [ '_pthread_ptr' , '_pthread_is_main_runtime_thread' , '_pthread_is_main_browser_thread' ] ,
1018
- $registerPthreadPtr__asm : true ,
1019
- $registerPthreadPtr__sig : 'viii' ,
1020
- $registerPthreadPtr : function ( pthreadPtr , isMainBrowserThread , isMainRuntimeThread ) {
1021
- pthreadPtr = pthreadPtr | 0 ;
1022
- isMainBrowserThread = isMainBrowserThread | 0 ;
1023
- isMainRuntimeThread = isMainRuntimeThread | 0 ;
1024
- __pthread_ptr = pthreadPtr ;
1025
- __pthread_is_main_browser_thread = isMainBrowserThread ;
1026
- __pthread_is_main_runtime_thread = isMainRuntimeThread ;
1027
- } ,
1028
-
1029
- // Public pthread_self() function which returns a unique ID for the thread.
1030
- pthread_self__deps : [ '_pthread_ptr' ] ,
1031
- pthread_self__asm : true ,
1032
- pthread_self__sig : 'i' ,
1033
- pthread_self : function ( ) {
1034
- return __pthread_ptr | 0 ;
1035
- } ,
1036
-
1037
- emscripten_is_main_runtime_thread__asm : true ,
1038
- emscripten_is_main_runtime_thread__sig : 'i' ,
1039
- emscripten_is_main_runtime_thread__deps : [ '_pthread_is_main_runtime_thread' ] ,
1040
- emscripten_is_main_runtime_thread : function ( ) {
1041
- // Semantically the same as testing "!ENVIRONMENT_IS_PTHREAD" outside the asm.js scope
1042
- return __pthread_is_main_runtime_thread | 0 ;
1043
- } ,
1044
-
1045
- emscripten_is_main_browser_thread__asm : true ,
1046
- emscripten_is_main_browser_thread__sig : 'i' ,
1047
- emscripten_is_main_browser_thread__deps : [ '_pthread_is_main_browser_thread' ] ,
1048
- emscripten_is_main_browser_thread : function ( ) {
1049
- // Semantically the same as testing "!ENVIRONMENT_IS_WORKER" outside the asm.js scope
1050
- return __pthread_is_main_browser_thread | 0 ;
1051
- } ,
1052
-
1053
1016
pthread_getschedparam : function ( thread , policy , schedparam ) {
1054
1017
if ( ! policy && ! schedparam ) return ERRNO_CODES . EINVAL ;
1055
1018
0 commit comments