4
4
// found in the LICENSE file.
5
5
6
6
var LibraryPThread = {
7
- $PThread__postset : 'if (!ENVIRONMENT_IS_PTHREAD ) PThread.initMainThreadBlock(); else PThread.initWorker();' ,
7
+ $PThread__postset : 'if (!ENVIRONMENT_IS_WORKER ) PThread.initMainThreadBlock(); else PThread.initWorker();' ,
8
8
$PThread__deps : [ '$PROCINFO' , '_register_pthread_ptr' ,
9
9
'emscripten_main_thread_process_queued_calls' ,
10
10
'$ERRNO_CODES' , 'emscripten_futex_wake' , '_kill_thread' ,
@@ -35,7 +35,7 @@ var LibraryPThread = {
35
35
_emscripten_register_main_browser_thread_id ( PThread . mainThreadBlock ) ;
36
36
} ,
37
37
initMainThreadBlock : function ( ) {
38
- if ( ENVIRONMENT_IS_PTHREAD ) return undefined ;
38
+ if ( ENVIRONMENT_IS_WORKER ) return undefined ;
39
39
40
40
#if PTHREAD_POOL_SIZE > 0
41
41
var requestedPoolSize = { { { PTHREAD_POOL_SIZE } } } ;
@@ -161,7 +161,7 @@ var LibraryPThread = {
161
161
}
162
162
163
163
// Call into the musl function that runs destructors of all thread-specific data.
164
- if ( ENVIRONMENT_IS_PTHREAD && threadInfoStruct ) ___pthread_tsd_run_dtors ( ) ;
164
+ if ( ENVIRONMENT_IS_WORKER && threadInfoStruct ) ___pthread_tsd_run_dtors ( ) ;
165
165
} ,
166
166
167
167
// Called when we are performing a pthread_exit(), either explicitly called by programmer,
@@ -188,7 +188,7 @@ var LibraryPThread = {
188
188
_emscripten_futex_wake ( tb + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ;
189
189
__register_pthread_ptr ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
190
190
threadInfoStruct = 0 ;
191
- if ( ENVIRONMENT_IS_PTHREAD ) {
191
+ if ( ENVIRONMENT_IS_WORKER ) {
192
192
// Note: in theory we would like to return any offscreen canvases back to the main thread,
193
193
// but if we ever fetched a rendering context for them that would not be valid, so we don't try.
194
194
postMessage ( { 'cmd' : 'exit' } ) ;
@@ -483,7 +483,7 @@ var LibraryPThread = {
483
483
} ,
484
484
485
485
_kill_thread : function ( pthread_ptr ) {
486
- if ( ENVIRONMENT_IS_PTHREAD ) throw 'Internal Error! _kill_thread() can only ever be called from main application thread!' ;
486
+ if ( ENVIRONMENT_IS_WORKER ) throw 'Internal Error! _kill_thread() can only ever be called from main application thread!' ;
487
487
if ( ! pthread_ptr ) throw 'Internal Error! Null pthread_ptr in _kill_thread!' ;
488
488
{ { { makeSetValue ( 'pthread_ptr' , C_STRUCTS . pthread . self , 0 , 'i32' ) } } } ;
489
489
var pthread = PThread . pthreads [ pthread_ptr ] ;
@@ -496,7 +496,7 @@ var LibraryPThread = {
496
496
} ,
497
497
498
498
_cleanup_thread : function ( pthread_ptr ) {
499
- if ( ENVIRONMENT_IS_PTHREAD ) throw 'Internal Error! _cleanup_thread() can only ever be called from main application thread!' ;
499
+ if ( ENVIRONMENT_IS_WORKER ) throw 'Internal Error! _cleanup_thread() can only ever be called from main application thread!' ;
500
500
if ( ! pthread_ptr ) throw 'Internal Error! Null pthread_ptr in _cleanup_thread!' ;
501
501
{ { { makeSetValue ( 'pthread_ptr' , C_STRUCTS . pthread . self , 0 , 'i32' ) } } } ;
502
502
var pthread = PThread . pthreads [ pthread_ptr ] ;
@@ -507,14 +507,14 @@ var LibraryPThread = {
507
507
} ,
508
508
509
509
_cancel_thread : function ( pthread_ptr ) {
510
- if ( ENVIRONMENT_IS_PTHREAD ) throw 'Internal Error! _cancel_thread() can only ever be called from main application thread!' ;
510
+ if ( ENVIRONMENT_IS_WORKER ) throw 'Internal Error! _cancel_thread() can only ever be called from main application thread!' ;
511
511
if ( ! pthread_ptr ) throw 'Internal Error! Null pthread_ptr in _cancel_thread!' ;
512
512
var pthread = PThread . pthreads [ pthread_ptr ] ;
513
513
pthread . worker . postMessage ( { 'cmd' : 'cancel' } ) ;
514
514
} ,
515
515
516
516
_spawn_thread : function ( threadParams ) {
517
- if ( ENVIRONMENT_IS_PTHREAD ) throw 'Internal Error! _spawn_thread() can only ever be called from main application thread!' ;
517
+ if ( ENVIRONMENT_IS_WORKER ) throw 'Internal Error! _spawn_thread() can only ever be called from main application thread!' ;
518
518
519
519
var worker = PThread . getNewWorker ( ) ;
520
520
@@ -703,7 +703,7 @@ var LibraryPThread = {
703
703
704
704
// Synchronously proxy the thread creation to main thread if possible. If we need to transfer ownership of objects, then
705
705
// proxy asynchronously via postMessage.
706
- if ( ENVIRONMENT_IS_PTHREAD && ( transferList . length === 0 || error ) ) {
706
+ if ( ENVIRONMENT_IS_WORKER && ( transferList . length === 0 || error ) ) {
707
707
return _emscripten_sync_run_in_main_thread_4 ( { { { cDefine ( 'EM_PROXIED_PTHREAD_CREATE' ) } } } , pthread_ptr , attr , start_routine , arg ) ;
708
708
}
709
709
@@ -792,7 +792,7 @@ var LibraryPThread = {
792
792
transferList : transferList
793
793
} ;
794
794
795
- if ( ENVIRONMENT_IS_PTHREAD ) {
795
+ if ( ENVIRONMENT_IS_WORKER ) {
796
796
// The prepopulated pool of web workers that can host pthreads is stored in the main JS thread. Therefore if a
797
797
// pthread is attempting to spawn a new thread, the thread creation must be deferred to the main JS thread.
798
798
threadParams . cmd = 'spawnThread' ;
@@ -809,7 +809,7 @@ var LibraryPThread = {
809
809
// TODO HACK! Remove this function, it is a JS side copy of the function pthread_testcancel() in library_pthread.c.
810
810
// Just call pthread_testcancel() everywhere.
811
811
_pthread_testcancel_js : function ( ) {
812
- if ( ! ENVIRONMENT_IS_PTHREAD ) return ;
812
+ if ( ! ENVIRONMENT_IS_WORKER ) return ;
813
813
if ( ! threadInfoStruct ) return ;
814
814
var cancelDisabled = Atomics . load ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . canceldisable } } } ) >> 2 ) ;
815
815
if ( cancelDisabled ) return ;
@@ -833,11 +833,11 @@ var LibraryPThread = {
833
833
err ( 'pthread_join attempted on a null thread pointer!' ) ;
834
834
return ERRNO_CODES . ESRCH ;
835
835
}
836
- if ( ENVIRONMENT_IS_PTHREAD && selfThreadId == thread ) {
836
+ if ( ENVIRONMENT_IS_WORKER && selfThreadId == thread ) {
837
837
err ( 'PThread ' + thread + ' is attempting to join to itself!' ) ;
838
838
return ERRNO_CODES . EDEADLK ;
839
839
}
840
- else if ( ! ENVIRONMENT_IS_PTHREAD && PThread . mainThreadBlock == thread ) {
840
+ else if ( ! ENVIRONMENT_IS_WORKER && PThread . mainThreadBlock == thread ) {
841
841
err ( 'Main thread ' + thread + ' is attempting to join to itself!' ) ;
842
842
return ERRNO_CODES . EDEADLK ;
843
843
}
@@ -864,7 +864,7 @@ var LibraryPThread = {
864
864
if ( status ) { { { makeSetValue ( 'status' , 0 , 'threadExitCode' , 'i32' ) } } } ;
865
865
Atomics . store ( HEAPU32 , ( thread + { { { C_STRUCTS . pthread . detached } } } ) >> 2 , 1 ) ; // Mark the thread as detached.
866
866
867
- if ( ! ENVIRONMENT_IS_PTHREAD ) __cleanup_thread ( thread ) ;
867
+ if ( ! ENVIRONMENT_IS_WORKER ) __cleanup_thread ( thread ) ;
868
868
else postMessage ( { 'cmd' : 'cleanupThread' , 'thread' : thread } ) ;
869
869
return 0 ;
870
870
}
@@ -876,8 +876,8 @@ var LibraryPThread = {
876
876
__pthread_testcancel_js ( ) ;
877
877
// In main runtime thread (the thread that initialized the Emscripten C runtime and launched main()), assist pthreads in performing operations
878
878
// that they need to access the Emscripten main runtime for.
879
- if ( ! ENVIRONMENT_IS_PTHREAD ) _emscripten_main_thread_process_queued_calls ( ) ;
880
- _emscripten_futex_wait ( thread + { { { C_STRUCTS . pthread . threadStatus } } } , threadStatus , ENVIRONMENT_IS_PTHREAD ? 100 : 1 ) ;
879
+ if ( ! ENVIRONMENT_IS_WORKER ) _emscripten_main_thread_process_queued_calls ( ) ;
880
+ _emscripten_futex_wait ( thread + { { { C_STRUCTS . pthread . threadStatus } } } , threadStatus , ENVIRONMENT_IS_WORKER ? 100 : 1 ) ;
881
881
}
882
882
} ,
883
883
@@ -909,7 +909,7 @@ var LibraryPThread = {
909
909
return ERRNO_CODES . ESRCH ;
910
910
}
911
911
if ( signal != 0 ) {
912
- if ( ! ENVIRONMENT_IS_PTHREAD ) __kill_thread ( thread ) ;
912
+ if ( ! ENVIRONMENT_IS_WORKER ) __kill_thread ( thread ) ;
913
913
else postMessage ( { 'cmd ': 'killThread ', 'thread ': thread } ) ;
914
914
}
915
915
return 0 ;
@@ -931,7 +931,7 @@ var LibraryPThread = {
931
931
return ERRNO_CODES . ESRCH ;
932
932
}
933
933
Atomics . compareExchange ( HEAPU32 , ( thread + { { { C_STRUCTS . pthread . threadStatus } } } ) >> 2 , 0 , 2 ) ; // Signal the thread that it needs to cancel itself.
934
- if ( ! ENVIRONMENT_IS_PTHREAD ) __cancel_thread ( thread ) ;
934
+ if ( ! ENVIRONMENT_IS_WORKER ) __cancel_thread ( thread ) ;
935
935
else postMessage ( { 'cmd ': 'cancelThread ', 'thread ': thread } ) ;
936
936
return 0 ;
937
937
} ,
@@ -955,7 +955,7 @@ var LibraryPThread = {
955
955
956
956
pthread_exit__deps : [ 'exit' ] ,
957
957
pthread_exit : function ( status ) {
958
- if ( ! ENVIRONMENT_IS_PTHREAD ) _exit ( status ) ;
958
+ if ( ! ENVIRONMENT_IS_WORKER ) _exit ( status ) ;
959
959
else PThread . threadExit ( status ) ;
960
960
#if WASM_BACKEND
961
961
// pthread_exit is marked noReturn, so we must not return from it.
@@ -996,7 +996,7 @@ var LibraryPThread = {
996
996
emscripten_is_main_runtime_thread__sig : 'i' ,
997
997
emscripten_is_main_runtime_thread__deps : [ '_pthread_is_main_runtime_thread' ] ,
998
998
emscripten_is_main_runtime_thread : function ( ) {
999
- return __pthread_is_main_runtime_thread | 0 ; // Semantically the same as testing "!ENVIRONMENT_IS_PTHREAD " outside the asm.js scope
999
+ return __pthread_is_main_runtime_thread | 0 ; // Semantically the same as testing "!ENVIRONMENT_IS_WORKER " outside the asm.js scope
1000
1000
} ,
1001
1001
1002
1002
emscripten_is_main_browser_thread__asm : true ,
@@ -1105,7 +1105,7 @@ var LibraryPThread = {
1105
1105
pthread_cleanup_push : function ( routine , arg ) {
1106
1106
if ( PThread . exitHandlers === null ) {
1107
1107
PThread . exitHandlers = [ ] ;
1108
- if ( ! ENVIRONMENT_IS_PTHREAD ) {
1108
+ if ( ! ENVIRONMENT_IS_WORKER ) {
1109
1109
__ATEXIT__ . push ( function ( ) { PThread . runExitHandlers ( ) ; } ) ;
1110
1110
}
1111
1111
}
@@ -1135,13 +1135,13 @@ var LibraryPThread = {
1135
1135
emscripten_futex_wait__deps : [ '_main_thread_futex_wait_address' , 'emscripten_main_thread_process_queued_calls' ] ,
1136
1136
emscripten_futex_wait : function ( addr , val , timeout ) {
1137
1137
if ( addr <= 0 || addr > HEAP8 . length || addr & 3 != 0 ) return - { { { cDefine ( 'EINVAL' ) } } } ;
1138
- // dump('futex_wait addr:' + addr + ' by thread: ' + _pthread_self() + (ENVIRONMENT_IS_PTHREAD ?'(pthread)':'') + '\n');
1138
+ // dump('futex_wait addr:' + addr + ' by thread: ' + _pthread_self() + (ENVIRONMENT_IS_WORKER ?'(pthread)':'') + '\n');
1139
1139
if ( ENVIRONMENT_IS_WORKER ) {
1140
1140
#if PTHREADS_PROFILING
1141
1141
PThread . setThreadStatusConditional ( _pthread_self ( ) , { { { cDefine ( 'EM_THREAD_STATUS_RUNNING' ) } } } , { { { cDefine ( 'EM_THREAD_STATUS_WAITFUTEX' ) } } } ) ;
1142
1142
#endif
1143
1143
var ret = Atomics . wait ( HEAP32 , addr >> 2 , val , timeout ) ;
1144
- // dump('futex_wait done by thread: ' + _pthread_self() + (ENVIRONMENT_IS_PTHREAD ?'(pthread)':'') + '\n');
1144
+ // dump('futex_wait done by thread: ' + _pthread_self() + (ENVIRONMENT_IS_WORKER ?'(pthread)':'') + '\n');
1145
1145
#if PTHREADS_PROFILING
1146
1146
PThread . setThreadStatusConditional ( _pthread_self ( ) , { { { cDefine ( 'EM_THREAD_STATUS_WAITFUTEX' ) } } } , { { { cDefine ( 'EM_THREAD_STATUS_RUNNING' ) } } } ) ;
1147
1147
#endif
@@ -1192,7 +1192,7 @@ var LibraryPThread = {
1192
1192
// Waking (at least) INT_MAX waiters is defined to mean wake all callers.
1193
1193
// For Atomics.notify() API Infinity is to be passed in that case.
1194
1194
if ( count >= { { { cDefine ( 'INT_MAX' ) } } } ) count = Infinity ;
1195
- // dump('futex_wake addr:' + addr + ' by thread: ' + _pthread_self() + (ENVIRONMENT_IS_PTHREAD ?'(pthread)':'') + '\n');
1195
+ // dump('futex_wake addr:' + addr + ' by thread: ' + _pthread_self() + (ENVIRONMENT_IS_WORKER ?'(pthread)':'') + '\n');
1196
1196
1197
1197
// See if main thread is waiting on this address? If so, wake it up by resetting its wake location to zero.
1198
1198
// Note that this is not a fair procedure, since we always wake main thread first before any workers, so
0 commit comments