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
@@ -81,10 +81,10 @@ var LibraryPThread = {
81
81
} ) ;
82
82
#endif
83
83
84
- // Pass the thread address inside the asm.js scope to store it for fast
85
- // access that avoids the need for a FFI out. Global constructors trying
84
+ // Pass the thread address to the native code where they stored in wasm
85
+ // globals which act as a form of TLS. Global constructors trying
86
86
// to access this value will read the wrong value, but that is UB anyway.
87
- registerPthreadPtr ( PThread . mainThreadBlock , /*isMainBrowserThread=*/ ! ENVIRONMENT_IS_WORKER , /*isMainRuntimeThread=*/ 1 ) ;
87
+ __emscripten_thread_init ( PThread . mainThreadBlock , /*isMainBrowserThread=*/ ! ENVIRONMENT_IS_WORKER , /*isMainRuntimeThread=*/ 1 ) ;
88
88
_emscripten_register_main_browser_thread_id ( PThread . mainThreadBlock ) ;
89
89
} ,
90
90
initWorker: function ( ) {
@@ -218,7 +218,7 @@ var LibraryPThread = {
218
218
PThread . runExitHandlers ( ) ;
219
219
220
220
_emscripten_futex_wake ( tb + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ;
221
- registerPthreadPtr ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
221
+ __emscripten_thread_init ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
222
222
threadInfoStruct = 0 ;
223
223
if ( ENVIRONMENT_IS_PTHREAD ) {
224
224
// Note: in theory we would like to return any offscreen canvases back to the main thread,
@@ -234,7 +234,7 @@ var LibraryPThread = {
234
234
Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . threadStatus } } } ) >> 2 , 1 ) ; // Mark the thread as no longer running.
235
235
_emscripten_futex_wake ( threadInfoStruct + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ; // wake all threads
236
236
threadInfoStruct = selfThreadId = 0 ; // Not hosting a pthread anymore in this worker, reset the info structures to null.
237
- registerPthreadPtr ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
237
+ __emscripten_thread_init ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
238
238
postMessage ( { 'cmd' : 'cancelDone' } ) ;
239
239
} ,
240
240
@@ -1005,46 +1005,9 @@ var LibraryPThread = {
1005
1005
throw 'unwind' ;
1006
1006
} ,
1007
1007
1008
- _pthread_ptr : 0 ,
1009
1008
_pthread_is_main_runtime_thread : 0 ,
1010
1009
_pthread_is_main_browser_thread : 0 ,
1011
1010
1012
- $registerPthreadPtr__deps : [ '_pthread_ptr' , '_pthread_is_main_runtime_thread' , '_pthread_is_main_browser_thread' ] ,
1013
- $registerPthreadPtr__asm : true ,
1014
- $registerPthreadPtr__sig : 'viii' ,
1015
- $registerPthreadPtr : function ( pthreadPtr , isMainBrowserThread , isMainRuntimeThread ) {
1016
- pthreadPtr = pthreadPtr | 0 ;
1017
- isMainBrowserThread = isMainBrowserThread | 0 ;
1018
- isMainRuntimeThread = isMainRuntimeThread | 0 ;
1019
- __pthread_ptr = pthreadPtr ;
1020
- __pthread_is_main_browser_thread = isMainBrowserThread ;
1021
- __pthread_is_main_runtime_thread = isMainRuntimeThread ;
1022
- } ,
1023
-
1024
- // Public pthread_self() function which returns a unique ID for the thread.
1025
- pthread_self__deps : [ '_pthread_ptr' ] ,
1026
- pthread_self__asm : true ,
1027
- pthread_self__sig : 'i' ,
1028
- pthread_self : function ( ) {
1029
- return __pthread_ptr | 0 ;
1030
- } ,
1031
-
1032
- emscripten_is_main_runtime_thread__asm : true ,
1033
- emscripten_is_main_runtime_thread__sig : 'i' ,
1034
- emscripten_is_main_runtime_thread__deps : [ '_pthread_is_main_runtime_thread' ] ,
1035
- emscripten_is_main_runtime_thread : function ( ) {
1036
- // Semantically the same as testing "!ENVIRONMENT_IS_PTHREAD" outside the asm.js scope
1037
- return __pthread_is_main_runtime_thread | 0 ;
1038
- } ,
1039
-
1040
- emscripten_is_main_browser_thread__asm : true ,
1041
- emscripten_is_main_browser_thread__sig : 'i' ,
1042
- emscripten_is_main_browser_thread__deps : [ '_pthread_is_main_browser_thread' ] ,
1043
- emscripten_is_main_browser_thread : function ( ) {
1044
- // Semantically the same as testing "!ENVIRONMENT_IS_WORKER" outside the asm.js scope
1045
- return __pthread_is_main_browser_thread | 0 ;
1046
- } ,
1047
-
1048
1011
pthread_getschedparam : function ( thread , policy , schedparam ) {
1049
1012
if ( ! policy && ! schedparam ) return ERRNO_CODES . EINVAL ;
1050
1013
0 commit comments