Allow emscripten_atomic_wait_suspending to return synchronously when possible#26947
Conversation
aece5ac to
3f54471
Compare
f2b3b85 to
8868476
Compare
|
I have a nice followup to which I think makes this solution nicer: f5cc8ee |
|
Sounds reasonable. |
|
@tlively Do you think this approach makes sense then? i.e. the version where we return a promise and only suspend sometimes? If so, are you OK landing this change? (with the "await_unchecked") as a separate followup? |
|
Actually maybe lets just land #26954 first |
This works with ASYNCIFY like the existing `emscripten_promise_await` but is a lot simpler since it only handles the fulfilled case. In this case we can simple return the result directly without needing to allocate a `em_promise_result_t` struct to deal with the out param (i.e. no memory access needed). This can be useful in cases where we don't want to handle the rejections case. Split out from #26947
8868476 to
c5a41e9
Compare
|
OK, this is now rebase on top of #26954. PTAL! |
5e69766 to
9cd0cdb
Compare
| 'MAX_WEBGL_VERSION': 0, | ||
| 'BUILD_AS_WORKER': 1, | ||
| 'LINK_AS_CXX': 1, | ||
| 'SHARED_MEMORY': 0, |
There was a problem hiding this comment.
This is pretty in the weeds. These to phases of gen_sig_info.py run with use_cxx=True, which doesn't (can't) include musl C internal headers (which don't work in C++ mode).
However, since SHARED_MEMORY defaults to enabled in gen_sig_info we incldue libatomic.js in the build and end up with this error without this change:
$ tools/maint/gen_sig_info.py
generating signatures ...
.. {'WASMFS': 1, 'JS_LIBRARIES': [], 'USE_SDL': 0, 'MAX_WEBGL_VERSION': 0, 'BUILD_AS_WORKER': 1, 'LINK_AS_CXX': 1, 'AUTO_JS_LIBRARIES': 0} + None
/tmp/tmpwetk6rye.cpp:351:11: error: use of undeclared identifier '_emscripten_atomic_wait_promise'
351 | (void*)&_emscripten_atomic_wait_promise,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Its kind of hard to explain, but the only output of this script is the libsig.js and if that has not changed we can be sure we didn't break the script. i.e. there are no other / subtle breakage that can occur from changing gen_sig_info.py
Followup to the initial version landed in emscripten-core#26941
9cd0cdb to
1f44a44
Compare
emscripten_atomic_wait_suspending to return synchronously when possible
Followup to the initial version landed in #26941. This version of the code allows for reporting of synchronous results without actually suspending.
The implementation of
emscripten_atomic_wait_suspendingis not in libc, and it works by first calling a non-JSPI function which can return a promise, or a sync result. Then, only in the case that a promise is returned do we actually need to suspend using a JSPI call.