rust-index: add Sync bound to all relevant mmap-derived values
authorRaphaël Gomès <rgomes@octobus.net>
Thu, 26 Oct 2023 15:26:19 +0200
changeset 51233 ca81cd96000a
parent 51232 3551f2a1c963
child 51234 59183a19954e
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.
rust/hg-core/src/revlog/index.rs
rust/hg-cpython/src/revlog.rs
--- a/rust/hg-core/src/revlog/index.rs	Tue Oct 31 18:09:43 2023 +0100
+++ b/rust/hg-core/src/revlog/index.rs	Thu Oct 26 15:26:19 2023 +0200
@@ -85,7 +85,7 @@
 /// happened. This makes it transparent for the callers.
 struct IndexData {
     /// Immutable bytes, most likely taken from disk
-    bytes: Box<dyn Deref<Target = [u8]> + Send>,
+    bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>,
     /// Used when stripping index contents, keeps track of the start of the
     /// first stripped revision, which is used to give a slice of the
     /// `bytes` field.
@@ -95,7 +95,7 @@
 }
 
 impl IndexData {
-    pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send>) -> Self {
+    pub fn new(bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>) -> Self {
         Self {
             bytes,
             truncation: None,
@@ -328,7 +328,7 @@
     /// Create an index from bytes.
     /// Calculate the start of each entry when is_inline is true.
     pub fn new(
-        bytes: Box<dyn Deref<Target = [u8]> + Send>,
+        bytes: Box<dyn Deref<Target = [u8]> + Send + Sync>,
         default_header: IndexHeader,
     ) -> Result<Self, HgError> {
         let header =
--- a/rust/hg-cpython/src/revlog.rs	Tue Oct 31 18:09:43 2023 +0100
+++ b/rust/hg-cpython/src/revlog.rs	Thu Oct 26 15:26:19 2023 +0200
@@ -520,7 +520,7 @@
     data: PyObject,
 ) -> PyResult<(
     PyBuffer,
-    Box<dyn std::ops::Deref<Target = [u8]> + Send + 'static>,
+    Box<dyn std::ops::Deref<Target = [u8]> + Send + Sync + 'static>,
 )> {
     let buf = PyBuffer::get(py, &data)?;
     let len = buf.item_count();