diff --git a/src/raw.rs b/src/raw.rs index 4beeb81..79c4127 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -98,8 +98,8 @@ extern "C" { pub fn pkg_file_iter_index_type(iterator: PPkgFileIterator) -> *const c_char; } -pub fn pkg_cache_get() -> &'static CACHE { - &CACHE +pub fn pkg_cache_get_singleton() -> &'static CACHE_SINGLETON { + &CACHE_SINGLETON } #[derive(Debug)] @@ -111,7 +111,7 @@ unsafe impl Send for CacheHolder {} lazy_static! { #[derive(Debug)] - pub static ref CACHE: Mutex = { + pub static ref CACHE_SINGLETON: Mutex = { unsafe { init_config_system(); Mutex::new(CacheHolder { diff --git a/src/sane.rs b/src/sane.rs index 07da043..3287940 100644 --- a/src/sane.rs +++ b/src/sane.rs @@ -14,14 +14,14 @@ use citer::RawIterator; /// from which most functionality can be accessed. #[derive(Debug)] pub struct Cache { - ptr: &'static raw::CACHE, + ptr_mutex: &'static raw::CACHE_SINGLETON, } impl Cache { /// Get a reference to the singleton. pub fn get_singleton() -> Cache { Cache { - ptr: raw::pkg_cache_get(), + ptr_mutex: raw::pkg_cache_get_singleton(), } } @@ -31,7 +31,7 @@ impl Cache { /// /// See the module documentation for apologies about how this isn't an iterator. pub fn iter(&mut self) -> CIterator { - let lock = self.ptr.lock().unwrap(); + let lock = self.ptr_mutex.lock().expect("poisoned mutex"); unsafe { let raw_iter = raw::pkg_cache_pkg_iter(lock.ptr); PkgIterator::new(lock, raw_iter) @@ -43,7 +43,7 @@ impl Cache { /// /// The returned iterator will either be at the end, or at a package with the name. pub fn find_by_name(&mut self, name: &str) -> CIterator { - let lock = self.ptr.lock().unwrap(); + let lock = self.ptr_mutex.lock().expect("poisoned mutex"); unsafe { let name = ffi::CString::new(name).unwrap(); let ptr = raw::pkg_cache_find_name(lock.ptr, name.as_ptr()); @@ -55,7 +55,7 @@ impl Cache { /// /// The returned iterator will either be at the end, or at a matching package. pub fn find_by_name_arch(&mut self, name: &str, arch: &str) -> CIterator { - let lock = self.ptr.lock().unwrap(); + let lock = self.ptr_mutex.lock().expect("poisoned mutex"); unsafe { let name = ffi::CString::new(name).unwrap(); let arch = ffi::CString::new(arch).unwrap(); @@ -83,7 +83,7 @@ impl Cache { let left = ffi::CString::new(left).unwrap(); let right = ffi::CString::new(right).unwrap(); - let lock = self.ptr.lock().unwrap(); + let lock = self.ptr_mutex.lock().expect("poisoned mutex"); raw::pkg_cache_compare_versions(lock.ptr, left.as_ptr(), right.as_ptr()).cmp(&0) } }