Export runtime keepalive API to native code. NFC#17160
Conversation
Sometimes it is useful to be able to make the runtime as alive without also unwinding. See test_pthread_proxying_cpp.cpp for an example of this. I also have use case for emscripten_runtime_keepalive_check() in #17153
3dcf8a2 to
cd1adeb
Compare
| const mangledName = mangleCSymbolName(target); | ||
| lib[x] = new Function(args, `${ret}${mangledName}(${args});`); |
There was a problem hiding this comment.
Yes, without this you can't have the target of the alias be an internal JS function (i.e. one that starts with $).
I could rename the internal $runtimeKeepalivePush so that we don't need aliases at all but that would make the patch way bigger and should probable be a followup.
| emscripten_runtime_keepalive_push: '$runtimeKeepalivePush', | ||
| emscripten_runtime_keepalive_pop: '$runtimeKeepalivePop', | ||
| emscripten_runtime_keepalive_check: function() { | ||
| // keepRuntimeAlive is a runtime function rather than a library function, |
There was a problem hiding this comment.
What is the difference between a runtime function and a library function?
There was a problem hiding this comment.
A runtime function is just a few function in the JS preamble/postamble/etc. There is no way to include or exclude runtime functions.
Library functions are the ones defined in these specifically-formed library files (mostly src/library.js and src/library_*.js. Library functions are included on demand and never included unless somebody depends on them. We tend to prefer library functions these day because they have no impact on users codesize unless they are actually needed.
|
|
||
| void emscripten_runtime_keepalive_push(); | ||
| void emscripten_runtime_keepalive_pop(); | ||
| EM_BOOL emscripten_runtime_keepalive_check(); |
There was a problem hiding this comment.
Why does EM_BOOL exist? Why not just use int or bool here?
There was a problem hiding this comment.
It exists yes. It pre-dates my involvement with the project.
I guess we could use <stdbool.h> these days but I'm not sure I'd want to force all emscripten users to include <stdbool.h>.. since it does pollute the global namespace.
Sometimes it is useful to be able to make the runtime as alive without
also unwinding. See test_pthread_proxying_cpp.cpp for an example of
this.
I also have use case for emscripten_runtime_keepalive_check() in #17153