Skip to content

Commit f04b8c2

Browse files
Filip LundgrenFilip Lundgren
authored andcommitted
Support preallocated pthread & wasm worker from blob
1 parent d0d9966 commit f04b8c2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/library_pthread.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,20 @@ var LibraryPThread = {
9898
},
9999
initMainThread() {
100100
#if PTHREAD_POOL_SIZE
101-
var pthreadPoolSize = {{{ PTHREAD_POOL_SIZE }}};
102-
// Start loading up the Worker pool, if requested.
103-
while (pthreadPoolSize--) {
104-
PThread.allocateUnusedWorker();
101+
preallocateWorkers = () => {
102+
var pthreadPoolSize = {{{ PTHREAD_POOL_SIZE }}};
103+
// Start loading up the Worker pool, if requested.
104+
while (pthreadPoolSize--) {
105+
PThread.allocateUnusedWorker();
106+
}
107+
};
108+
#if expectToReceiveOnModule('mainScriptUrlOrBlobPromise')
109+
if (Module['mainScriptUrlOrBlobPromise']) {
110+
Module['mainScriptUrlOrBlobPromise'].then(preallocateWorkers);
111+
} else
112+
#endif
113+
{
114+
preallocateWorkers();
105115
}
106116
#endif
107117
#if !MINIMAL_RUNTIME

src/library_wasm_worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ if (ENVIRONMENT_IS_WASM_WORKER
182182
'mem': wasmMemory,
183183
#else
184184
'wasm': wasmModule,
185-
'js': Module['mainScriptUrlOrBlob'] || _scriptName,
185+
'js': URL.createObjectURL(Module["mainScriptUrlOrBlob"]) || _scriptName,
186186
'wasmMemory': wasmMemory,
187187
#endif
188188
'sb': stackLowestAddress, // sb = stack bottom (lowest stack address, SP points at this when stack is full)

0 commit comments

Comments
 (0)