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

Option for reader #52

Merged
merged 2 commits into from
Nov 12, 2023
Merged

Option for reader #52

merged 2 commits into from
Nov 12, 2023

Conversation

adetaylor
Copy link
Collaborator

Relates to #50.

Thanks to @djmitche for making me look at this again!
Comment on lines +386 to 397
let mut reading_stuff = state.reader.take();
// Is there read in progress?
while read_in_progress {
while reading_stuff.is_none() {
// - If yes, release CACHE mutex, WAIT on condvar atomically
state = self.read_completed.wait(state).unwrap();
// check cache again
if let Some(bytes_read_from_cache) = state.read_from_cache(pos, buf) {
log::debug!("Deferred cache success");
return Ok(bytes_read_from_cache);
}
read_in_progress = state.read_in_progress;
reading_stuff = state.reader.take();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth encapsulating this into a State method or other utility, in such a way that it uses RAII to put the value back. It's almost 100 lines later that this value is returned to the Option!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like that idea! Will do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had a crack at this but it turned out I didn't like the results so much. I prefer the current explicit step since then it's obvious that we put back the reading stuff before releasing the mutex. I fiddled around a bit with RAII guards and with a .with_reading_stuff(FnOnce) type arrangement but neither was sufficiently delightful.

@adetaylor adetaylor marked this pull request as ready for review November 10, 2023 18:16
@adetaylor adetaylor merged commit ada62cf into main Nov 12, 2023
11 checks passed
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