@@ -171,19 +171,7 @@ var LibraryPThread = {
171
171
if ( ENVIRONMENT_IS_PTHREAD && threadInfoStruct ) ___pthread_tsd_run_dtors ( ) ;
172
172
} ,
173
173
174
- // Called when we are performing a pthread_exit(), either explicitly called by programmer,
175
- // or implicitly when leaving the thread main function.
176
- threadExit : function ( exitCode ) {
177
- var tb = _pthread_self ( ) ;
178
- if ( tb ) { // If we haven't yet exited?
179
- #if ASSERTIONS
180
- err ( 'Pthread 0x' + tb . toString ( 16 ) + ' exited.' ) ;
181
- #endif
182
- #if PTHREADS_PROFILING
183
- var profilerBlock = Atomics . load ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . profilerBlock } } } ) >> 2 ) ;
184
- Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . profilerBlock } } } ) >> 2 , 0 ) ;
185
- _free ( profilerBlock ) ;
186
- #endif
174
+ onThreadExit : function ( tb , exitCode ) {
187
175
// Disable all cancellation so that executing the cleanup handlers won't trigger another JS
188
176
// canceled exception to be thrown.
189
177
Atomics . store ( HEAPU32 , ( tb + { { { C_STRUCTS . pthread . canceldisable } } } ) >> 2 , 1 /*PTHREAD_CANCEL_DISABLE*/ ) ;
@@ -193,11 +181,28 @@ var LibraryPThread = {
193
181
Atomics . store ( HEAPU32 , ( tb + { { { C_STRUCTS . pthread . threadExitCode } } } ) >> 2 , exitCode ) ;
194
182
// When we publish this, the main thread is free to deallocate the thread object and we are done.
195
183
// Therefore set threadInfoStruct = 0; above to 'release' the object in this worker thread.
196
- Atomics . store ( HEAPU32 , ( tb + { { { C_STRUCTS . pthread . threadStatus } } } ) >> 2 , 1 ) ;
184
+ Atomics . store ( HEAPU32 , ( tb + { { { C_STRUCTS . pthread . threadStatus } } } ) >> 2 , 1 ) ; // Mark the thread as no longer running.
197
185
198
186
_emscripten_futex_wake ( tb + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ;
187
+ _emscripten_futex_wake ( tb + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ; // wake all threads
199
188
__register_pthread_ptr( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
200
189
threadInfoStruct = 0 ;
190
+ } ,
191
+
192
+ // Called when we are performing a pthread_exit(), either explicitly called by programmer,
193
+ // or implicitly when leaving the thread main function.
194
+ threadExit : function ( exitCode ) {
195
+ var tb = _pthread_self ( ) ;
196
+ if ( tb ) { // If we haven't yet exited?
197
+ #if ASSERTIONS
198
+ err ( 'Pthread 0x' + tb . toString ( 16 ) + ' exited.' ) ;
199
+ #endif
200
+ #if PTHREADS_PROFILING
201
+ var profilerBlock = Atomics . load ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . profilerBlock } } } ) >> 2 ) ;
202
+ Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . profilerBlock } } } ) >> 2 , 0 ) ;
203
+ _free ( profilerBlock ) ;
204
+ #endif
205
+ PThread . onThreadExit ( tb , exitCode ) ;
201
206
if ( ENVIRONMENT_IS_PTHREAD ) {
202
207
// Note: in theory we would like to return any offscreen canvases back to the main thread,
203
208
// but if we ever fetched a rendering context for them that would not be valid, so we don't try.
@@ -207,16 +212,8 @@ var LibraryPThread = {
207
212
} ,
208
213
209
214
threadCancel : function ( ) {
210
- // Disable all cancellation so that executing the cleanup handlers won't trigger another JS
211
- // canceled exception to be thrown.
212
- Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . canceldisable } } } ) >> 2 , 1 /*PTHREAD_CANCEL_DISABLE*/ ) ;
213
- Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . cancelasync } } } ) >> 2 , 0 /*PTHREAD_CANCEL_DEFERRED*/ ) ;
214
- PThread . runExitHandlers ( ) ;
215
- Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . threadExitCode } } } ) >> 2 , - 1 /*PTHREAD_CANCELED*/ ) ;
216
- Atomics . store ( HEAPU32 , ( threadInfoStruct + { { { C_STRUCTS . pthread . threadStatus } } } ) >> 2 , 1 ) ; // Mark the thread as no longer running.
217
- _emscripten_futex_wake ( threadInfoStruct + { { { C_STRUCTS . pthread . threadStatus } } } , { { { cDefine ( 'INT_MAX' ) } } } ) ; // wake all threads
218
- threadInfoStruct = selfThreadId = 0 ; // Not hosting a pthread anymore in this worker, reset the info structures to null.
219
- __register_pthread_ptr ( 0 , 0 , 0 ) ; // Unregister the thread block also inside the asm.js scope.
215
+ PThread . onThreadExit ( threadInfoStruct , - 1 /*PTHREAD_CANCELED*/ ) ;
216
+ selfThreadId = 0 ;
220
217
postMessage ( { 'cmd' : 'cancelDone' } ) ;
221
218
} ,
222
219
0 commit comments