projects
/
rust-101.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update solutions dependencies
[rust-101.git]
/
solutions
/
src
/
counter.rs
diff --git
a/solutions/src/counter.rs
b/solutions/src/counter.rs
index afea9d04654d5e85452f7233318b93c588645879..319058e51796f2e7fd34bf9686687276137a5861 100644
(file)
--- a/
solutions/src/counter.rs
+++ b/
solutions/src/counter.rs
@@
-11,19
+11,19
@@
impl ConcurrentCounter {
}
pub fn increment(&self, by: usize) {
}
pub fn increment(&self, by: usize) {
- let mut counter = self.0.write().unwrap
(
);
+ let mut counter = self.0.write().unwrap
_or_else(|e| e.into_inner()
);
*counter = *counter + by;
}
pub fn compare_and_inc(&self, test: usize, by: usize) {
*counter = *counter + by;
}
pub fn compare_and_inc(&self, test: usize, by: usize) {
- let mut counter = self.0.write().unwrap
(
);
+ let mut counter = self.0.write().unwrap
_or_else(|e| e.into_inner()
);
if *counter == test {
*counter += by;
}
}
pub fn get(&self) -> usize {
if *counter == test {
*counter += by;
}
}
pub fn get(&self) -> usize {
- let counter = self.0.read().unwrap
(
);
+ let counter = self.0.read().unwrap
_or_else(|e| e.into_inner()
);
*counter
}
}
*counter
}
}