7
7
var LibraryPThread = {
8
8
$PThread__postset : 'if (!ENVIRONMENT_IS_PTHREAD) PThread.initMainThreadBlock();' ,
9
9
$PThread__deps : [ '_emscripten_thread_init' ,
10
- 'emscripten_register_main_browser_thread_id' ,
11
10
'emscripten_futex_wake' , '$killThread' ,
12
11
'$cancelThread' , '$cleanupThread' ,
13
- #if USE_ASAN || USE_LSAN
14
- , '$withBuiltinMalloc'
15
- #endif
16
12
] ,
17
13
$PThread : {
18
14
// Contains all Workers that are idle/unused and not currently hosting an
@@ -37,33 +33,7 @@ var LibraryPThread = {
37
33
}
38
34
#endif
39
35
} ,
40
- initRuntime : function ( ) {
41
- #if USE_ASAN || USE_LSAN
42
- // When sanitizers are enabled, malloc is normally instrumented to call
43
- // sanitizer code that checks some things about pthreads. As we are just
44
- // setting up the main thread here, and are not ready for such calls,
45
- // call malloc directly.
46
- withBuiltinMalloc ( function ( ) {
47
- #endif
48
-
49
- var tb = _malloc ( { { { C_STRUCTS . pthread . __size__ } } } ) ;
50
-
51
- for ( var i = 0 ; i < { { { C_STRUCTS . pthread . __size__ } } } / 4 ; ++ i ) HEAPU32 [ tb / 4 + i ] = 0 ;
52
-
53
- // The pthread struct has a field that points to itself - this is used as
54
- // a magic ID to detect whether the pthread_t structure is 'alive'.
55
- { { { makeSetValue ( 'tb' , C_STRUCTS . pthread . self , 'tb' , 'i32' ) } } } ;
56
-
57
- // pthread struct robust_list head should point to itself.
58
- var headPtr = tb + { { { C_STRUCTS . pthread . robust_list } } } ;
59
- { { { makeSetValue ( 'headPtr' , 0 , 'headPtr' , 'i32' ) } } } ;
60
-
61
- // Allocate memory for thread-local storage.
62
- var tlsMemory = _malloc ( { { { cDefine ( 'PTHREAD_KEYS_MAX' ) * 4 } } } ) ;
63
- for ( var i = 0 ; i < { { { cDefine ( 'PTHREAD_KEYS_MAX' ) } } } ; ++ i ) HEAPU32 [ tlsMemory / 4 + i ] = 0 ;
64
- Atomics . store ( HEAPU32 , ( tb + { { { C_STRUCTS . pthread . tsd } } } ) >> 2 , tlsMemory ) ; // Init thread-local-storage memory array.
65
- Atomics . store ( HEAPU32 , ( tb + { { { C_STRUCTS . pthread . tid } } } ) >> 2 , tb ) ; // Main thread ID.
66
-
36
+ initRuntime : function ( tb ) {
67
37
#if PTHREADS_PROFILING
68
38
PThread . createProfilerBlock ( tb ) ;
69
39
PThread . setThreadName ( tb , "Browser main thread" ) ;
@@ -74,14 +44,9 @@ var LibraryPThread = {
74
44
// globals which act as a form of TLS. Global constructors trying
75
45
// to access this value will read the wrong value, but that is UB anyway.
76
46
__emscripten_thread_init ( tb , /*isMainBrowserThread=*/ ! ENVIRONMENT_IS_WORKER , /*isMainRuntimeThread=*/ 1 ) ;
77
- _emscripten_register_main_browser_thread_id ( tb ) ;
78
47
#if ASSERTIONS
79
48
PThread . mainRuntimeThread = true ;
80
49
#endif
81
-
82
- #if USE_ASAN || USE_LSAN
83
- } ) ;
84
- #endif
85
50
} ,
86
51
initWorker : function ( ) {
87
52
#if USE_CLOSURE_COMPILER
@@ -568,6 +533,7 @@ var LibraryPThread = {
568
533
pthread . worker . postMessage ( { 'cmd' : 'cancel' } ) ;
569
534
} ,
570
535
536
+ $spawnThread__deps : [ '$zeroMemory' ] ,
571
537
$spawnThread : function ( threadParams ) {
572
538
if ( ENVIRONMENT_IS_PTHREAD ) throw 'Internal Error! spawnThread() can only ever be called from main application thread!' ;
573
539
@@ -582,10 +548,8 @@ var LibraryPThread = {
582
548
PThread . runningWorkers . push ( worker ) ;
583
549
584
550
// Allocate memory for thread-local storage and initialize it to zero.
585
- var tlsMemory = _malloc ( { { { cDefine ( 'PTHREAD_KEYS_MAX' ) } } } * 4 ) ;
586
- for ( var i = 0 ; i < { { { cDefine ( 'PTHREAD_KEYS_MAX' ) } } } ; ++ i ) {
587
- { { { makeSetValue ( 'tlsMemory' , 'i*4' , 0 , 'i32' ) } } } ;
588
- }
551
+ var tlsMemory = _malloc ( { { { cDefine ( 'PTHREAD_KEYS_MAX' ) * 4 } } } ) ;
552
+ zeroMemory ( tlsMemory , { { { cDefine ( 'PTHREAD_KEYS_MAX' ) * 4 } } } ) ;
589
553
590
554
var stackHigh = threadParams . stackBase + threadParams . stackSize ;
591
555
@@ -822,7 +786,7 @@ var LibraryPThread = {
822
786
// Allocate thread block (pthread_t structure).
823
787
var threadInfoStruct = _malloc ( { { { C_STRUCTS . pthread . __size__ } } } ) ;
824
788
// zero-initialize thread structure.
825
- for ( var i = 0 ; i < { { { C_STRUCTS . pthread . __size__ } } } >> 2 ; ++ i ) HEAPU32 [ ( threadInfoStruct >> 2 ) + i ] = 0 ;
789
+ zeroMemory ( threadInfoStruct , { { { C_STRUCTS . pthread . __size__ } } } ) ;
826
790
{ { { makeSetValue ( 'pthread_ptr' , 0 , 'threadInfoStruct' , 'i32' ) } } } ;
827
791
828
792
// The pthread struct has a field that points to itself - this is used as a
0 commit comments