From b1733218d0c0454bc23b554277bc158a43d46489 Mon Sep 17 00:00:00 2001 From: Andrea Corradi Date: Sun, 4 Apr 2021 16:15:35 +0200 Subject: [PATCH] Wrap Env and Cache using Arc --- src/db_options.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/db_options.rs b/src/db_options.rs index 4913151bf..50e2d281e 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -15,7 +15,7 @@ use std::ffi::{CStr, CString}; use std::mem; use std::path::Path; -use std::rc::Rc; +use std::sync::Arc; use libc::{self, c_char, c_int, c_uchar, c_uint, c_void, size_t}; @@ -48,7 +48,7 @@ impl Drop for CacheWrapper { } } -pub struct Cache(pub(crate) Rc); +pub struct Cache(pub(crate) Arc); impl Cache { /// Create a lru cache with capacity @@ -57,7 +57,7 @@ impl Cache { if cache.is_null() { Err(Error::new("Could not create Cache".to_owned())) } else { - Ok(Cache(Rc::new(CacheWrapper { inner: cache }))) + Ok(Cache(Arc::new(CacheWrapper { inner: cache }))) } } @@ -93,6 +93,8 @@ impl Cache { /// /// Note: currently, C API behinds C++ API for various settings. /// See also: `rocksdb/include/env.h` +pub struct Env(Arc); + struct EnvWrapper { inner: *mut ffi::rocksdb_env_t, } @@ -105,8 +107,6 @@ impl Drop for EnvWrapper { } } -pub struct Env(Rc); - impl Env { /// Returns default env pub fn default() -> Result { @@ -114,7 +114,7 @@ impl Env { if env.is_null() { Err(Error::new("Could not create mem env".to_owned())) } else { - Ok(Env(Rc::new(EnvWrapper { inner: env }))) + Ok(Env(Arc::new(EnvWrapper { inner: env }))) } } @@ -125,7 +125,7 @@ impl Env { if env.is_null() { Err(Error::new("Could not create mem env".to_owned())) } else { - Ok(Env(Rc::new(EnvWrapper { inner: env }))) + Ok(Env(Arc::new(EnvWrapper { inner: env }))) } }