comparison rust/hg-core/src/revlog/index.rs @ 51233:ca81cd96000a

rust-index: add Sync bound to all relevant mmap-derived values All readonly mmaps are Sync as far as Rust is concerned. Integrity of the mmap'ed file is a concern separate to Rust's memory model, since it requires out-of-program handling via locks, etc. This will help when we start sharing the Rust Index with Python.
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 26 Oct 2023 15:26:19 +0200
parents 1b23aaf5eb7b
children 59183a19954e
comparison
equal deleted inserted replaced
51232:3551f2a1c963 51233:ca81cd96000a
83 /// Abstracts the access to the index bytes since they can be spread between 83 /// Abstracts the access to the index bytes since they can be spread between
84 /// the immutable (bytes) part and the mutable (added) part if any appends 84 /// the immutable (bytes) part and the mutable (added) part if any appends
85 /// happened. This makes it transparent for the callers. 85 /// happened. This makes it transparent for the callers.
86 struct IndexData { 86 struct IndexData {
87 /// Immutable bytes, most likely taken from disk 87 /// Immutable bytes, most likely taken from disk
88 bytes: Box<dyn Deref<Target = [u8]> + Send>, 88 bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>,
89 /// Used when stripping index contents, keeps track of the start of the 89 /// Used when stripping index contents, keeps track of the start of the
90 /// first stripped revision, which is used to give a slice of the 90 /// first stripped revision, which is used to give a slice of the
91 /// `bytes` field. 91 /// `bytes` field.
92 truncation: Option<usize>, 92 truncation: Option<usize>,
93 /// Bytes that were added after reading the index 93 /// Bytes that were added after reading the index
94 added: Vec<u8>, 94 added: Vec<u8>,
95 } 95 }
96 96
97 impl IndexData { 97 impl IndexData {
98 pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send>) -> Self { 98 pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>) -> Self {
99 Self { 99 Self {
100 bytes, 100 bytes,
101 truncation: None, 101 truncation: None,
102 added: vec![], 102 added: vec![],
103 } 103 }
326 326
327 impl Index { 327 impl Index {
328 /// Create an index from bytes. 328 /// Create an index from bytes.
329 /// Calculate the start of each entry when is_inline is true. 329 /// Calculate the start of each entry when is_inline is true.
330 pub fn new( 330 pub fn new(
331 bytes: Box<dyn Deref<Target = [u8]> + Send>, 331 bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>,
332 default_header: IndexHeader, 332 default_header: IndexHeader,
333 ) -> Result<Self, HgError> { 333 ) -> Result<Self, HgError> {
334 let header = 334 let header =
335 IndexHeader::parse(bytes.as_ref())?.unwrap_or(default_header); 335 IndexHeader::parse(bytes.as_ref())?.unwrap_or(default_header);
336 336