-
Notifications
You must be signed in to change notification settings - Fork 110
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
Adding wait_while
to the loom Condvar.
#167
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,22 @@ impl Condvar { | |
Ok(guard) | ||
} | ||
|
||
/// Blocks the current thread until this condition variable receives a | ||
/// notification and the given condition returns false. | ||
pub fn wait_while<'a, T, F>( | ||
&self, | ||
mut guard: MutexGuard<'a, T>, | ||
mut condition: F, | ||
) -> LockResult<MutexGuard<'a, T>> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could elide these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I tried. Eliding the lifetime completely gives a warning because it’s part of the MutexGuard struct. Trying to make it anonymous gives a complete error because it tries to use the same lifetime as &self. Also messing with signature seems like a bad idea since we’re trying match what’s in std. |
||
where | ||
F: FnMut(&mut T) -> bool, | ||
{ | ||
while condition(&mut *guard) { | ||
guard = self.wait(guard)?; | ||
} | ||
Ok(guard) | ||
} | ||
|
||
/// Waits on this condition variable for a notification, timing out after a | ||
/// specified duration. | ||
pub fn wait_timeout<'a, T>( | ||
|
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.
Nit, take it or leave it: we could just copy and paste the entire doc comment from
std::sync::Condvar
here, since the API is identical. But, it doesn't really matter (and it looks like other methods on our mockCondvar
don't reproduce the entirestd
comment...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.
I thought about that, but yeah. It didn't seem like that would fit in with the existing comments that were there.