@@ -268,10 +268,7 @@ var LibraryPThread = {
268
268
}
269
269
270
270
if ( cmd === 'processProxyingQueue' ) {
271
- // TODO: Must post message to main Emscripten thread in PROXY_TO_WORKER mode.
272
- _emscripten_proxy_execute_queue ( d [ 'queue' ] ) ;
273
- // Decrement the ref count
274
- Atomics . sub ( HEAP32 , d [ 'queue' ] >> 2 , 1 ) ;
271
+ executeNotifiedProxyingQueue ( d [ 'queue' ] ) ;
275
272
} else if ( cmd === 'spawnThread' ) {
276
273
spawnThread ( d ) ;
277
274
} else if ( cmd === 'cleanupThread' ) {
@@ -1047,19 +1044,25 @@ var LibraryPThread = {
1047
1044
return { { { makeDynCall ( 'ii' , 'ptr' ) } } } ( arg ) ;
1048
1045
} ,
1049
1046
1047
+ $executeNotifiedProxyingQueue : function ( queue ) {
1048
+ try {
1049
+ // Only execute the queue if we have a live pthread runtime. We
1050
+ // implement pthread_self to return 0 if there is no live runtime.
1051
+ // TODO: Use `callUserCallback` to correctly handle unwinds, etc. once
1052
+ // `runtimeExited` is correctly unset on workers.
1053
+ if ( _pthread_self ( ) ) {
1054
+ _emscripten_proxy_execute_queue ( queue ) ;
1055
+ }
1056
+ } finally {
1057
+ // Always decrement the ref count.
1058
+ Atomics . sub ( HEAP32 , queue >> 2 , 1 ) ;
1059
+ }
1060
+ } ,
1061
+
1062
+ _emscripten_notify_proxying_queue__deps : [ '$executeNotifiedProxyingQueue' ] ,
1050
1063
_emscripten_notify_proxying_queue : function ( targetThreadId , currThreadId , mainThreadId , queue ) {
1051
1064
if ( targetThreadId == currThreadId ) {
1052
- setTimeout ( ( ) => {
1053
- // Only execute the queue if we have a live pthread runtime. We
1054
- // implement pthread_self to return 0 if there is no live runtime.
1055
- // TODO: Use `callUserCallback` to correctly handle unwinds, etc. once
1056
- // `runtimeExited` is correctly unset on workers.
1057
- if ( _pthread_self ( ) ) {
1058
- _emscripten_proxy_execute_queue ( queue ) ;
1059
- }
1060
- // Decrement the ref count
1061
- Atomics . sub ( HEAP32 , queue >> 2 , 1 ) ;
1062
- } ) ;
1065
+ setTimeout ( ( ) => executeNotifiedProxyingQueue ( queue ) ) ;
1063
1066
} else if ( ENVIRONMENT_IS_PTHREAD ) {
1064
1067
postMessage ( { 'targetThread' : targetThreadId , 'cmd' : 'processProxyingQueue' , 'queue' : queue } ) ;
1065
1068
} else {
0 commit comments