Skip to content

Add blocking-based poll_oneoff to support clock_nanosleep #88

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kateinoigakukun
Copy link
Contributor

This commit adds a blocking-based poll_oneoff implementation to support clock_nanosleep in wasi-libc. This implementation is very simple and only supports a single subscription for now but is enough for clock_nanosleep to work.

This commit adds a blocking-based `poll_oneoff` implementation to support
`clock_nanosleep` in wasi-libc. This implementation is very simple and
only supports a single subscription for now but is enough for
`clock_nanosleep` to work.
// TODO: For now, we only support a single subscription just to be enough for wasi-libc's
// clock_nanosleep.
if (nsubscriptions > 1) {
return wasi.ERRNO_NOTSUP;
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe add a debug.log() for each ERRNO_NOTSUP error explaining what the error is?

src/wasi.ts Outdated
}
const clockid = buffer.getUint32(in_ptr + 16, true);
const timeout = buffer.getBigUint64(in_ptr + 24, true);
const flags = buffer.getUint16(in_ptr + 36, true);
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe add parsing for the subscription type to wasi_defs.ts? You can use the Iovec class as inspiration for the interface to expose.

https://github.com/WebAssembly/WASI/blob/3d5e0553cd01dd4d6e2c06ad2a702ee9dda17b7f/legacy/preview1/witx/typenames.witx#L547-L603

: getNow() + timeout;
while (endTime > getNow()) {
// block until the timeout is reached
}
Copy link
Owner

@bjorn3 bjorn3 Feb 16, 2025

Choose a reason for hiding this comment

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

Not an ideal solution as this will block user interaction if it runs on the main thread and unnecessarily uses the cpu which especially on mobile devices is bad, but I guess there isn't really a better way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, JSPI could be a mitigation but I think it's too early to use it here

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