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.
This commit is contained in:
Huon Wilson
2014-02-13 17:17:50 +11:00
parent fba32ea79f
commit 76a59fd6e2
13 changed files with 134 additions and 94 deletions

View File

@@ -157,7 +157,7 @@ pub mod dl {
unsafe {
// dlerror isn't thread safe, so we need to lock around this entire
// sequence
lock.lock();
let _guard = lock.lock();
let _old_error = dlerror();
let result = f();
@@ -168,7 +168,7 @@ pub mod dl {
} else {
Err(str::raw::from_c_str(last_error))
};
lock.unlock();
ret
}
}