aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2014-03-18 19:20:15 -0700
committerSteven Fackler <[email protected]>2014-03-18 19:20:15 -0700
commit53acce7a989a98d628d437bcef00dfcf1a927720 (patch)
tree77ec0b20000179b5d294870689b31626a5f837cc
parentSupport the dynlock API (diff)
downloadrust-openssl-53acce7a989a98d628d437bcef00dfcf1a927720.tar.xz
rust-openssl-53acce7a989a98d628d437bcef00dfcf1a927720.zip
Clean up locking code a bit
-rw-r--r--ssl/mod.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/ssl/mod.rs b/ssl/mod.rs
index 206eabf4..a5f95148 100644
--- a/ssl/mod.rs
+++ b/ssl/mod.rs
@@ -92,15 +92,7 @@ pub enum SslVerifyMode {
extern fn locking_function(mode: c_int, n: c_int, _file: *c_char,
_line: c_int) {
- unsafe {
- let mutex = (*MUTEXES).get_mut(n as uint);
-
- if mode & ffi::CRYPTO_LOCK != 0 {
- mutex.lock_noguard();
- } else {
- mutex.unlock_noguard();
- }
- }
+ unsafe { inner_lock(mode, (*MUTEXES).get_mut(n as uint)); }
}
extern fn dyn_create_function(_file: *c_char, _line: c_int) -> *c_void {
@@ -109,21 +101,21 @@ extern fn dyn_create_function(_file: *c_char, _line: c_int) -> *c_void {
extern fn dyn_lock_function(mode: c_int, l: *c_void, _file: *c_char,
_line: c_int) {
- unsafe {
- let mutex: &mut NativeMutex = cast::transmute(l);
-
- if mode & ffi::CRYPTO_LOCK != 0 {
- mutex.lock_noguard();
- } else {
- mutex.unlock_noguard();
- }
- }
+ unsafe { inner_lock(mode, cast::transmute(l)); }
}
extern fn dyn_destroy_function(l: *c_void, _file: *c_char, _line: c_int) {
unsafe { let _mutex: ~NativeMutex = cast::transmute(l); }
}
+unsafe fn inner_lock(mode: c_int, lock: &mut NativeMutex) {
+ if mode & ffi::CRYPTO_LOCK != 0 {
+ lock.lock_noguard();
+ } else {
+ lock.unlock_noguard();
+ }
+}
+
extern fn raw_verify(preverify_ok: c_int, x509_ctx: *ffi::X509_STORE_CTX)
-> c_int {
unsafe {