summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-12-08 18:12:44 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-12-09 09:47:36 +0100
commitffda43c082b79f7698152287b8236b6c0c9918ec (patch)
tree48b1486fed83b452f35b5f4da5841b9242a12df7
parent12741c1d0e8b0801f6dfb5963efabef069236ffd (diff)
buffered-reader: Don't explicitly storing the mapping.
- This makes file_unix::File Send and Sync.
-rw-r--r--buffered-reader/src/file_unix.rs20
-rw-r--r--buffered-reader/src/memory.rs5
2 files changed, 14 insertions, 11 deletions
diff --git a/buffered-reader/src/file_unix.rs b/buffered-reader/src/file_unix.rs
index 0b645f3c..8adca1e6 100644
--- a/buffered-reader/src/file_unix.rs
+++ b/buffered-reader/src/file_unix.rs
@@ -4,7 +4,7 @@
//! performance of the statistics example by ~10% over the
//! Generic.
-use libc::{c_void, size_t, mmap, munmap, PROT_READ, MAP_PRIVATE};
+use libc::{mmap, munmap, PROT_READ, MAP_PRIVATE};
use std::fmt;
use std::fs;
use std::io;
@@ -46,8 +46,6 @@ impl<'a, C: fmt::Debug> fmt::Debug for File<'a, C> {
enum Imp<'a, C: fmt::Debug> {
Generic(Generic<fs::File, C>),
MMAP {
- addr: *mut c_void,
- length: size_t,
reader: Memory<'a, C>,
}
}
@@ -56,10 +54,12 @@ impl<'a, C: fmt::Debug> Drop for Imp<'a, C> {
fn drop(&mut self) {
match self {
Imp::Generic(_) => (),
- Imp::MMAP { addr, length, .. } =>
+ Imp::MMAP { reader, } => {
+ let buf = reader.source_buffer();
unsafe {
- munmap(*addr, *length);
- },
+ munmap(buf.as_ptr() as *mut _, buf.len());
+ }
+ },
}
}
}
@@ -82,10 +82,10 @@ impl<'a, C: fmt::Debug> fmt::Debug for Imp<'a, C> {
f.debug_tuple("Generic")
.field(&g)
.finish(),
- Imp::MMAP { ref addr, ref length, ref reader } =>
+ Imp::MMAP { reader, } =>
f.debug_struct("MMAP")
- .field("addr", addr)
- .field("length", length)
+ .field("addr", &reader.source_buffer().as_ptr())
+ .field("length", &reader.source_buffer().len())
.field("reader", reader)
.finish(),
}
@@ -150,8 +150,6 @@ impl<'a, C: fmt::Debug> File<'a, C> {
Ok(File(
Imp::MMAP {
- addr,
- length,
reader: Memory::with_cookie(slice, cookie),
},
path.into(),
diff --git a/buffered-reader/src/memory.rs b/buffered-reader/src/memory.rs
index b09a3478..de2f61bb 100644
--- a/buffered-reader/src/memory.rs
+++ b/buffered-reader/src/memory.rs
@@ -55,6 +55,11 @@ impl<'a, C: fmt::Debug> Memory<'a, C> {
pub fn total_out(&self) -> usize {
return self.cursor;
}
+
+ #[allow(dead_code)]
+ pub(crate) fn source_buffer(&self) -> &[u8] {
+ self.buffer
+ }
}
impl<'a, C: fmt::Debug> io::Read for Memory<'a, C> {