diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-13 17:17:50 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-16 10:13:56 +1100 |
| commit | 76a59fd6e2d5c8c42193c047fd5eaba982d499f7 (patch) | |
| tree | a913c967de98b492f47fdd0bbd5a11cf0be96ed5 /src/libstd/comm | |
| parent | fba32ea79f1828ef441d91abca3635fad57f323d (diff) | |
| download | rust-76a59fd6e2d5c8c42193c047fd5eaba982d499f7.tar.gz rust-76a59fd6e2d5c8c42193c047fd5eaba982d499f7.zip | |
std: add an RAII unlocker to Mutex.
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
Diffstat (limited to 'src/libstd/comm')
| -rw-r--r-- | src/libstd/comm/shared.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs index 77bf2d7a68d..fcd00b70dd1 100644 --- a/src/libstd/comm/shared.rs +++ b/src/libstd/comm/shared.rs @@ -75,7 +75,7 @@ impl<T: Send> Packet<T> { select_lock: unsafe { Mutex::new() }, }; // see comments in inherit_blocker about why we grab this lock - unsafe { p.select_lock.lock() } + unsafe { p.select_lock.lock_noguard() } return p; } @@ -124,7 +124,7 @@ impl<T: Send> Packet<T> { // interfere with this method. After we unlock this lock, we're // signifying that we're done modifying self.cnt and self.to_wake and // the port is ready for the world to continue using it. - unsafe { self.select_lock.unlock() } + unsafe { self.select_lock.unlock_noguard() } } pub fn send(&mut self, t: T) -> bool { @@ -438,8 +438,7 @@ impl<T: Send> Packet<T> { // about looking at and dealing with to_wake. Once we have acquired the // lock, we are guaranteed that inherit_blocker is done. unsafe { - self.select_lock.lock(); - self.select_lock.unlock(); + let _guard = self.select_lock.lock(); } // Like the stream implementation, we want to make sure that the count |
