diff --git a/Cargo.toml b/Cargo.toml index 95862ed..4a06e31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ fs4 = "0.6" # to use direct functions on FreeBSD rustix = { version = "0", features = [ "fs" ]} crossbeam-channel = "0.5" +parking_lot = { version = "0.12.1" } # Binary dependencies docopt = "1.1" @@ -35,4 +36,4 @@ hdrhistogram = "7.5.2" quickcheck = "1.0.3" regex = "1.8.1" tempfile = "3.5.0" -chrono = "0.4.24" +chrono = "0.4.31" diff --git a/examples/bench.rs b/examples/bench.rs index c415d0a..a002032 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -42,7 +42,7 @@ fn main() { } pub fn precise_time_ns() -> u64 { - chrono::offset::Utc::now().timestamp_nanos() as u64 + chrono::offset::Utc::now().timestamp_nanos_opt().unwrap() as u64 } fn format_duration(n: u64) -> String { diff --git a/src/mmap_view_sync.rs b/src/mmap_view_sync.rs index 60982d9..7ff8495 100644 --- a/src/mmap_view_sync.rs +++ b/src/mmap_view_sync.rs @@ -1,4 +1,5 @@ use memmap2::{MmapMut, MmapOptions}; +use parking_lot::Mutex; use std::cell::UnsafeCell; use std::fmt; use std::fs::File; @@ -13,7 +14,7 @@ use std::sync::Arc; /// The view may be split into disjoint ranges, each of which will share the /// underlying memory map. pub struct MmapViewSync { - inner: Arc>, + inner: Arc>>, offset: usize, len: usize, } @@ -87,7 +88,7 @@ impl MmapViewSync { /// /// The caller must ensure that memory outside the `offset`/`len` range is not accessed. fn inner(&self) -> &MmapMut { - unsafe { &*self.inner.get() } + unsafe { &*self.inner.lock().get() } } /// Get a mutable reference to the inner mmap. @@ -95,7 +96,7 @@ impl MmapViewSync { /// The caller must ensure that memory outside the `offset`/`len` range is not accessed. #[allow(clippy::mut_from_ref)] fn inner_mut(&self) -> &mut MmapMut { - unsafe { &mut *self.inner.get() } + unsafe { &mut *self.inner.lock().get() } } /// Flushes outstanding view modifications to disk. @@ -147,7 +148,7 @@ impl From for MmapViewSync { fn from(mmap: MmapMut) -> MmapViewSync { let len = mmap.len(); MmapViewSync { - inner: Arc::new(UnsafeCell::new(mmap)), + inner: Arc::new(Mutex::new(UnsafeCell::new(mmap))), offset: 0, len, }