Repository navigation
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.
RFC: Add hid_read_interrupt API for thread-safe read cancellation #799
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: master
Are you sure you want to change the base?
RFC: Add hid_read_interrupt API for thread-safe read cancellation #799
Changes from all commits
f0a2db517fcf9ad834ec37c0c546e3cd21676e5dddc120ee4f107b53bef57f7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
[minor]
g_terminateis now written by this helper thread and read by the main thread's polling loop (L163).volatile sig_atomic_tis only defined for communication between a signal handler and the thread it interrupted. Between two threads it's a plain data race, which is UB in C++11, even though mainstream compilers handle it in practice.Suggested fix: use
std::atomic<int>(orstd::atomic<bool>) withstatic_assert(ATOMIC_INT_LOCK_FREE == 2, ...), which keeps the signal handler async-signal-safe. That covers both this race and the earlier lock-freedom concern.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.
[doc] A few notes on the concurrency contract:
hid_close()(andhid_exit()). The caller still has to keepdevvalid for the duration of the call.hid_is_read_interrupted()is described as "suitable for cross-thread observation", andhid_read_clear_interrupt()is only recommended not to overlap a read. Mayhid_read_clear_interrupt()overlaphid_read_interrupt()? See the race noted onlinux/hid.c.@returns ... Call hid_error(dev) to get the failure reason(L465-466): from the interrupting thread,hid_error(dev)isn't safe while another thread is operating on the device. Also, no backend currently ever returns -1 here. Consider documenting that the call doesn't fail, or not pointing athid_error(dev)for this function.Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.