summaryrefslogtreecommitdiffstats
path: root/src/notify_mutex.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/notify_mutex.rs')
-rw-r--r--src/notify_mutex.rs58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/notify_mutex.rs b/src/notify_mutex.rs
index 5aaa5d54..bd5a031e 100644
--- a/src/notify_mutex.rs
+++ b/src/notify_mutex.rs
@@ -3,39 +3,39 @@ use std::sync::{Arc, Condvar, Mutex};
/// combines a `Mutex` and `Condvar` to allow waiting for a change in the variable protected by the `Mutex`
#[derive(Clone, Debug)]
pub struct NotifyableMutex<T> {
- data: Arc<(Mutex<T>, Condvar)>,
+ data: Arc<(Mutex<T>, Condvar)>,
}
impl<T> NotifyableMutex<T> {
- ///
- pub fn new(start_value: T) -> Self {
- Self {
- data: Arc::new((Mutex::new(start_value), Condvar::new())),
- }
- }
+ ///
+ pub fn new(start_value: T) -> Self {
+ Self {
+ data: Arc::new((Mutex::new(start_value), Condvar::new())),
+ }
+ }
- ///
- pub fn wait(&self, condition: T)
- where
- T: PartialEq + Copy,
- {
- let mut data = self.data.0.lock().expect("lock err");
- while *data != condition {
- data = self.data.1.wait(data).expect("wait err");
- }
- }
+ ///
+ pub fn wait(&self, condition: T)
+ where
+ T: PartialEq + Copy,
+ {
+ let mut data = self.data.0.lock().expect("lock err");
+ while *data != condition {
+ data = self.data.1.wait(data).expect("wait err");
+ }
+ }
- ///
- pub fn set_and_notify(&self, value: T) {
- *self.data.0.lock().expect("set err") = value;
- self.data.1.notify_one();
- }
+ ///
+ pub fn set_and_notify(&self, value: T) {
+ *self.data.0.lock().expect("set err") = value;
+ self.data.1.notify_one();
+ }
- ///
- pub fn get(&self) -> T
- where
- T: Copy,
- {
- *self.data.0.lock().expect("get err")
- }
+ ///
+ pub fn get(&self) -> T
+ where
+ T: Copy,
+ {
+ *self.data.0.lock().expect("get err")
+ }
}