-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add emscripten_queue_microtask() API #25741
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
Open
juj
wants to merge
6
commits into
emscripten-core:main
Choose a base branch
from
juj:emscripten_queue_microtask
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+46
−0
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91daa78
Add emscripten_queue_microtask() API to enable use case described in …
juj 5b6c25d
fix sig
juj 27918d7
review
juj d18fa99
fix sig
juj f87c2db
Review
juj 5b30d3e
Merge remote-tracking branch 'origin/main' into emscripten_queue_micr…
juj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2374,6 +2374,12 @@ var LibraryHTML5 = { | |
| return requestAnimationFrame(tick); | ||
| }, | ||
|
|
||
| emscripten_queue_microtask: (cb, userData) => { | ||
| queueMicrotask(() => { | ||
| {{{ makeDynCall('vp', 'cb') }}}(userData); | ||
| }); | ||
| }, | ||
|
Collaborator
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. Move to |
||
|
|
||
| emscripten_get_device_pixel_ratio__proxy: 'sync', | ||
| emscripten_get_device_pixel_ratio: () => { | ||
| #if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright 2025 The Emscripten Authors. All rights reserved. | ||
| * Emscripten is available under two separate licenses, the MIT license and the | ||
| * University of Illinois/NCSA Open Source License. Both these licenses can be | ||
| * found in the LICENSE file. | ||
| */ | ||
|
|
||
| // Test emscripten_queue_microtask() behavior | ||
|
|
||
| #include <stdio.h> | ||
| #include <assert.h> | ||
| #include <emscripten.h> | ||
| #include <emscripten/html5.h> | ||
|
|
||
| void cb(void *userData) { | ||
| printf("cb\n"); | ||
| assert(userData == (void*)42); | ||
| emscripten_force_exit(0); | ||
| } | ||
|
|
||
| int main() { | ||
| emscripten_queue_microtask(cb, (void*)42); | ||
| emscripten_exit_with_live_runtime(); | ||
| return 99; // We won't reach here, but return non-zero value to guard against refactors that might exit() with this value. | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 probably needs to be wrapped in
callUserCallback.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.
Yeah.. Both the push and pop callback and callUserCallback are nice for some uses, but result in bloat :/
Added these, maybe callUserCallback() can be made zero-cost some day. (Or maybe it is so at least with Closure, not sure)
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.
We do need
callUserCallbackwhenever we enter user code from the event loop otherwise lots of things can break. A classic one is callingexit()from within the callback.IIRC the overhead of
callUserCallbackin MINIMAL_RUNTIME, where we don't have the same requirements is very close to zero. If you want to make reduce it to absolutely zero that seems like a good thing, but unrelated to this specific change.