implement Sync for DynamicIndexReader and FixedIndexReader

hyper's wrap_stream now needs this

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-28 10:33:41 +02:00
parent 236761a3e6
commit 5c1130df9f
3 changed files with 5 additions and 3 deletions

View File

@ -49,6 +49,7 @@ pub struct DynamicIndexReader {
// `index` is mmap()ed which cannot be thread-local so should be sendable // `index` is mmap()ed which cannot be thread-local so should be sendable
// FIXME: Introduce an mmap wrapper type for this? // FIXME: Introduce an mmap wrapper type for this?
unsafe impl Send for DynamicIndexReader {} unsafe impl Send for DynamicIndexReader {}
unsafe impl Sync for DynamicIndexReader {}
impl Drop for DynamicIndexReader { impl Drop for DynamicIndexReader {

View File

@ -45,6 +45,7 @@ pub struct FixedIndexReader {
// `index` is mmap()ed which cannot be thread-local so should be sendable // `index` is mmap()ed which cannot be thread-local so should be sendable
unsafe impl Send for FixedIndexReader {} unsafe impl Send for FixedIndexReader {}
unsafe impl Sync for FixedIndexReader {}
impl Drop for FixedIndexReader { impl Drop for FixedIndexReader {

View File

@ -7,7 +7,7 @@ use futures::*;
/// Trait to get digest list from index files /// Trait to get digest list from index files
/// ///
/// To allow easy iteration over all used chunks. /// To allow easy iteration over all used chunks.
pub trait IndexFile: Send { pub trait IndexFile {
fn index_count(&self) -> usize; fn index_count(&self) -> usize;
fn index_digest(&self, pos: usize) -> Option<&[u8; 32]>; fn index_digest(&self, pos: usize) -> Option<&[u8; 32]>;
fn index_bytes(&self) -> u64; fn index_bytes(&self) -> u64;
@ -49,14 +49,14 @@ pub trait IndexFile: Send {
/// ///
/// The reader simply returns a birary stream of 32 byte digest values. /// The reader simply returns a birary stream of 32 byte digest values.
pub struct DigestListEncoder { pub struct DigestListEncoder {
index: Box<dyn IndexFile>, index: Box<dyn IndexFile + Send + Sync>,
pos: usize, pos: usize,
count: usize, count: usize,
} }
impl DigestListEncoder { impl DigestListEncoder {
pub fn new(index: Box<dyn IndexFile>) -> Self { pub fn new(index: Box<dyn IndexFile + Send + Sync>) -> Self {
let count = index.index_count(); let count = index.index_count();
Self { index, pos: 0, count } Self { index, pos: 0, count }
} }