-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add centralized handling for calling user callbacks #13596
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
Conversation
61cdcb3
to
6b26bdc
Compare
6b26bdc
to
6b960dc
Compare
6b960dc
to
c4a4415
Compare
c4a4415
to
6f11253
Compare
6f11253
to
9732171
Compare
9732171
to
f10722c
Compare
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.
How about adding a specific test for the new keepalive functions, that is, without fetch or another high-level API?
f10722c
to
8ee81dc
Compare
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.
This LGTM overall, although I'm not as familiar with some of these details. I agree with @kripken that a more targeted test would be good, although it could be done in a followup since we want to start a release cut soon.
Actually I decided to just go for |
88ed81b
to
fcf052c
Compare
if (!Browser.mainLoop.timingSet) { | ||
{{{ runtimeKeepalivePush(); }}} | ||
Browser.mainLoop.timingSet = true; | ||
} |
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.
this change looks non-obvious. why unset this here, when it wasn't before? and why does that keep the runtime alive? where is the corresponding pop?
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.
This function (emscripten_set_main_loop_timing
) can be used to set the timing of an existing main loop. If the timing already set we don't want to repeated call runtimeKeepalivePush every time the timing is adjusted.
See 'main loop exiting..'
below in setMainLoop
for where the loops exits ad calls Pop
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.
I still find this confusing. Perhaps some comments could help, if I'm missing something.
It seems like we shouldn't care if the timing was set, but rather whether there was already a main loop running? That is, I'd expect to see a bool that says "I have pushed a runtime keepalive", or "already running" or such?
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 that is exactly what this is supposed to mean. I think after I investigated this I determined that a has timing been set
was the same things as "is running".. but you are correct I can come up with a better name and some comments.
src/library_sockfs.js
Outdated
$_setNetworkCallback: function(event, userData, callback) { | ||
function _callback(data) { | ||
{{{ runtimeKeepalivePop(); }}} | ||
if (!callback) return; |
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.
why wasn't this needed before, and why is it now?
1dce557
to
0cc4105
Compare
6f3cfb4
to
aa0ab7a
Compare
aa0ab7a
to
aadb94d
Compare
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.
lgtm % last comment
aadb94d
to
f06157a
Compare
This change also changes the way outstanding works keeps the runtime alive. We now use a counter rather than a single noExitRuntime variable so that once outstanding works is complete the thread can be shutdown if needed. The specific need for this comes the use case of running fetch thread and wanting to exit the thread once the fetch completes. Without this change `pthread_exit` from a fetch callback generated an `uncaught unwind` message on the console. In addition, it doesn't always make sense to call `pthread_exit`, (e.g. in cases where you want C++ descrutors on the stack to be called, or in cases where C++ threads are being used and pthread_exit` does not exist, or at least doesn't makes sense). With this solution the thread will exit automatically when returning from the fetch callback, no explict thread exit call needed.
f06157a
to
72f90a6
Compare
Added a new specific test for these new functions .. PTAL |
72f90a6
to
74189c2
Compare
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.
new test lgtm too
I believe this was an oversight when this code was refactored as part of #13596.
I believe this was an oversight when this code was refactored as part of #13596.
I believe this was an oversight when this code was refactored as part of #13596.
This change also changes the way outstanding works keeps the runtime
alive.
We now use a counter rather than a single noExitRuntime variable so
that once outstanding works is complete the thread can be shutdown
if needed.
The specific need for this comes the use case of running fetch thread
and wanting to exit the thread once the fetch completes. Without
this change
pthread_exit
from a fetch callback generated anuncaught unwind
message on the console.Also if one wants the fetch thread to become joinable there was no
way other than calling
pthread_exit
which has no parallel in the C++threads world and has issues around calling C++ destructors on the
stack. With this solution the thread will exit automatically when returning
from the fetch callback.