From 3ab1cc7a8f259ecc858bbc6fe28d9611802d0591 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 20 May 2018 15:24:38 -0700 Subject: [PATCH] Make Stack Sync + Send --- openssl/src/stack.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index 4d5c0a136..ac1e2a137 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -40,15 +40,8 @@ pub trait Stackable: ForeignType { /// An owned stack of `T`. pub struct Stack(*mut T::StackType); -impl Stack { - pub fn new() -> Result, ErrorStack> { - unsafe { - ffi::init(); - let ptr = cvt_p(OPENSSL_sk_new_null())?; - Ok(Stack(ptr as *mut _)) - } - } -} +unsafe impl Send for Stack {} +unsafe impl Sync for Stack {} impl Drop for Stack { fn drop(&mut self) { @@ -59,6 +52,16 @@ impl Drop for Stack { } } +impl Stack { + pub fn new() -> Result, ErrorStack> { + unsafe { + ffi::init(); + let ptr = cvt_p(OPENSSL_sk_new_null())?; + Ok(Stack(ptr as *mut _)) + } + } +} + impl iter::IntoIterator for Stack { type IntoIter = IntoIter; type Item = T; @@ -164,6 +167,9 @@ impl ExactSizeIterator for IntoIter {} pub struct StackRef(Opaque, PhantomData); +unsafe impl Send for StackRef {} +unsafe impl Sync for StackRef {} + impl ForeignTypeRef for StackRef { type CType = T::StackType; } -- GitLab