// This is the entry point file that is loaded first by each Web Worker
// that executes pthreads on the Emscripten application.
// All pthreads share the same Emscripten HEAP as SharedArrayBuffer
// with the main execution thread.
varbuffer;
varthreadInfoStruct=0;// Info area for this thread in Emscripten HEAP (shared). If zero, this worker is not currently hosting an executing pthread.
varselfThreadId=0;// The ID of this thread. 0 if not hosting a pthread.
vartempDoublePtr=0;// A temporary memory area for global float and double marshalling operations.
// Each thread has its own allocated stack space.
varSTACK_BASE=0;
varSTACKTOP=0;
varSTACK_MAX=0;
varENVIRONMENT_IS_PTHREAD=true;
// Cannot use console.log or console.error in a web worker, since that would risk a browser deadlock! https://bugzilla.mozilla.org/show_bug.cgi?id=1049091
// Therefore implement custom logging facility for threads running in a worker, which queue the messages to main thread to print.
// HACK: Some code in the wild has instead signatures of form 'void *ThreadMain()', which seems to be ok in native code.
// To emulate supporting both in test suites, use the following form. This is brittle!
if(typeofasm['dynCall_ii']!=='undefined'){
result=asm.dynCall_ii(e.data.start_routine,e.data.arg);// pthread entry points are always of signature 'void *ThreadMain(void *arg)'
}else{
result=asm.dynCall_i(e.data.start_routine);// as a hack, try signature 'i' as fallback.
}
}catch(e){
if(e==='Canceled!'){
PThread.threadCancel();
return;
}else{
Atomics.store(HEAPU32,(threadInfoStruct+4/*{{{ C_STRUCTS.pthread.threadExitCode }}}*/)>>2,-2/*A custom entry specific to Emscripten denoting that the thread crashed.*/);
Atomics.store(HEAPU32,(threadInfoStruct+0/*{{{ C_STRUCTS.pthread.threadStatus }}}*/)>>2,1);// Mark the thread as no longer running.
_emscripten_futex_wake(threadInfoStruct+0/*{{{ C_STRUCTS.pthread.threadStatus }}}*/,0x7FFFFFFF/*INT_MAX*/);// wake all threads
throwe;
}
}
// The thread might have finished without calling pthread_exit(). If so, then perform the exit operation ourselves.
// (This is a no-op if explicit pthread_exit() had been called prior.)
PThread.threadExit(result);
}elseif(e.data.cmd==='cancel'){// Main thread is asking for a pthread_cancel() on this thread.