From 53acce7a989a98d628d437bcef00dfcf1a927720 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 18 Mar 2014 19:20:15 -0700 Subject: [PATCH] Clean up locking code a bit --- ssl/mod.rs | 28 ++++++++++------------------ 1 file 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 {