-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Rewrite the old proxying API in terms of the new API #15880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6584c16
99f14f5
59a7bb3
faa6423
f241353
c3732d5
be9db82
5b6294e
e5ed1ba
8e17f91
be3de8f
f274a3c
d147a5a
64c1d42
4d5aa0e
b421b3c
2a21b12
82ea908
45f7b97
3b9cbd8
e9af913
fa0d198
54ae773
e4b05eb
28be33e
0fa13af
af9d2ce
d03c3da
9a89e69
f67a82e
18eebf5
67aa5ef
1db6681
72d7457
47fbd08
a5a151b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,9 +263,9 @@ var LibraryPThread = { | |
return; | ||
} | ||
|
||
if (cmd === 'processQueuedMainThreadWork') { | ||
if (cmd === 'processProxyingQueue') { | ||
// TODO: Must post message to main Emscripten thread in PROXY_TO_WORKER mode. | ||
_emscripten_main_thread_process_queued_calls(); | ||
_emscripten_proxy_execute_queue(d['queue']); | ||
} else if (cmd === 'spawnThread') { | ||
spawnThread(d); | ||
} else if (cmd === 'cleanupThread') { | ||
|
@@ -1040,29 +1040,6 @@ var LibraryPThread = { | |
return {{{ makeDynCall('ii', 'ptr') }}}(arg); | ||
}, | ||
|
||
// This function is called internally to notify target thread ID that it has messages it needs to | ||
// process in its message queue inside the Wasm heap. As a helper, the caller must also pass the | ||
// ID of the main browser thread to this function, to avoid needlessly ping-ponging between JS and | ||
// Wasm boundaries. | ||
_emscripten_notify_thread_queue: function(targetThreadId, mainThreadId) { | ||
if (targetThreadId == mainThreadId) { | ||
postMessage({'cmd' : 'processQueuedMainThreadWork'}); | ||
} else if (ENVIRONMENT_IS_PTHREAD) { | ||
postMessage({'targetThread': targetThreadId, 'cmd': 'processThreadQueue'}); | ||
} else { | ||
var pthread = PThread.pthreads[targetThreadId]; | ||
var worker = pthread && pthread.worker; | ||
if (!worker) { | ||
#if ASSERTIONS | ||
err('Cannot send message to thread with ID ' + targetThreadId + ', unknown thread ID!'); | ||
#endif | ||
return /*0*/; | ||
} | ||
worker.postMessage({'cmd' : 'processThreadQueue'}); | ||
} | ||
return 1; | ||
}, | ||
|
||
_emscripten_notify_proxying_queue: function(targetThreadId, currThreadId, mainThreadId, queue) { | ||
if (targetThreadId == currThreadId) { | ||
setTimeout(function() { _emscripten_proxy_execute_queue(queue); }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why turn this into a setTimeout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting.. I didn't see that the condition here changed from How was the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old code eagerly executed the proxied work if the target thread was the same as the current thread, so |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,10 +285,6 @@ self.onmessage = (e) => { | |
} | ||
} else if (e.data.target === 'setimmediate') { | ||
// no-op | ||
} else if (e.data.cmd === 'processThreadQueue') { | ||
if (Module['_pthread_self']()) { // If this thread is actually running? | ||
Module['_emscripten_current_thread_process_queued_calls'](); | ||
} | ||
} else if (e.data.cmd === 'processProxyingQueue') { | ||
if (Module['_pthread_self']()) { // If this thread is actually running? | ||
Module['_emscripten_proxy_execute_queue'](e.data.queue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to pass the queue pointer around or can we just assume its the system queue here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to pass the queue pointer around because this is the same code path used for both the system queue and user queues. Actually, I see that this ended up duplicated somehow as well. Will fix. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we save a little of JS codesize here by passing zero args and having
_emscripten_proxy_execute_queue
assume that NULL == system queue? Would save the extra post message packing / unpacking too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, potentially, but I would prefer to make it a clear-cut error for NULL to ever be passed to
emscripten_proxy_execute_queue
. Better for users to get an assertion failure (in debug builds) when they do that by accident than for the system queue to be executed.