-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: main
Are you sure you want to change the base?
Add blocking-based poll_oneoff
to support clock_nanosleep
#88
Conversation
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.
598a66d
to
ccc5dce
Compare
// 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; |
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.
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); |
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.
Maybe add parsing for the subscription
type to wasi_defs.ts? You can use the Iovec class as inspiration for the interface to expose.
: getNow() + timeout; | ||
while (endTime > getNow()) { | ||
// block until the timeout is reached | ||
} |
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.
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.
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, JSPI could be a mitigation but I think it's too early to use it here
This commit adds a blocking-based
poll_oneoff
implementation to supportclock_nanosleep
in wasi-libc. This implementation is very simple and only supports a single subscription for now but is enough forclock_nanosleep
to work.