Skip to content

Commit

Permalink
Merge pull request #58 from qdrant/flush-no-mut
Browse files Browse the repository at this point in the history
Mmap flush does not require mutable reference, use corret mut ref self
  • Loading branch information
timvisee committed Oct 2, 2023
2 parents e19cf06 + 7344bc0 commit a7de0f5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/mmap_view_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ impl MmapViewSync {

/// Get a reference to the inner mmap.
///
/// ## Unsafety
///
/// The caller must ensure that the file is not concurrently modified.
/// The caller must ensure that memory outside the `offset`/`len` range is not accessed.
fn inner(&self) -> &MmapMut {
unsafe { &*self.inner.get() }
}

/// Get a mutable reference to the inner mmap.
///
/// ## Unsafety
///
/// The caller must ensure that the file is not concurrently modified.
/// 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 {
fn inner_mut(&mut self) -> &mut MmapMut {
unsafe { &mut *self.inner.get() }
}

Expand All @@ -104,7 +109,7 @@ impl MmapViewSync {
/// map view are guaranteed to be durably stored. The file's metadata (including last
/// modification timestamp) may not be updated.
pub fn flush(&self) -> Result<()> {
self.inner_mut().flush_range(self.offset, self.len)
self.inner().flush_range(self.offset, self.len)
}

/// Returns the length of the memory map view.
Expand All @@ -127,7 +132,8 @@ impl MmapViewSync {
///
/// The caller must ensure that the file is not concurrently accessed.
pub unsafe fn as_mut_slice(&mut self) -> &mut [u8] {
&mut self.inner_mut()[self.offset..self.offset + self.len]
let (offset, len) = (self.offset, self.len);
&mut self.inner_mut()[offset..offset + len]
}

/// Clones the view of the memory map.
Expand Down Expand Up @@ -165,6 +171,7 @@ impl fmt::Debug for MmapViewSync {
}
}

#[cfg(test)]
unsafe impl Sync for MmapViewSync {}
unsafe impl Send for MmapViewSync {}

Expand Down

0 comments on commit a7de0f5

Please sign in to comment.