Skip to content
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

Mac: Update endpoints when interface alt setting is changed #50

Merged
merged 2 commits into from
Apr 25, 2024

Conversation

alexmoon
Copy link
Contributor

The set of available endpoints can change when an interface's alt setting is changed, so on Mac we need to refresh our cached set of endpoints.

This necessitates wrapping the BTreeMap in a Mutex so it can be updated through the shared self reference in set_alt_setting.

I also changed IoKitInterface::endpoints to take a &self reference instead of &mut self. This seems sound from my inspection, but it should be reviewed carefully in case I missed something.

The set of available endpoints can change when an interface's alt setting is changed, so on Mac we need to refresh our cached set of endpoints.
let endpoints = self.interface.endpoints()?;
debug!("Found endpoints: {endpoints:?}");

*self.endpoints.lock().unwrap() = endpoints;
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this should take the lock before calling SetAlternateInterface and self.interface.endpoints() to ensure consistency if multiple threads call set_alt_setting concurrently.

Which would be a silly thing to do and I don't know how a caller could possibly know what endpoints to use afterward without doing their own synchronization, but if we have the Mutex here, might as well take full advantage of it.

}

pub fn clear_halt(&self, endpoint: u8) -> Result<(), Error> {
debug!("Clear halt, endpoint {endpoint:02x}");
let ep = self
.endpoints
let endpoints = self.endpoints.lock().unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

And this one should release the lock before the blocking call to ClearPipeStallBothEnds, to avoid blocking other endpoints from creating transfers while the call completes synchronously.

@kevinmehall kevinmehall merged commit d1072b0 into kevinmehall:main Apr 25, 2024
4 checks passed
@kevinmehall
Copy link
Owner

Thanks!

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