Skip to content

Export runtime keepalive API to native code. NFC #17160

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

Merged
merged 1 commit into from
Jun 6, 2022
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 6, 2022

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

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
@sbc100 sbc100 requested review from tlively and kripken June 6, 2022 20:17
@sbc100 sbc100 force-pushed the expose_keepalive_api branch from 3dcf8a2 to cd1adeb Compare June 6, 2022 20:20
Comment on lines +299 to +300
const mangledName = mangleCSymbolName(target);
lib[x] = new Function(args, `${ret}${mangledName}(${args});`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between a runtime function and a library function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -26,6 +26,10 @@ void emscripten_set_immediate_loop(EM_BOOL (*cb)(void *userData), void *userData
long emscripten_set_interval(void (*cb)(void *userData), double intervalMsecs, void *userData);
void emscripten_clear_interval(long setIntervalId);

void emscripten_runtime_keepalive_push();
void emscripten_runtime_keepalive_pop();
EM_BOOL emscripten_runtime_keepalive_check();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does EM_BOOL exist? Why not just use int or bool here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sbc100 sbc100 merged commit 1f3080a into main Jun 6, 2022
@sbc100 sbc100 deleted the expose_keepalive_api branch June 6, 2022 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants