diff --git a/heed/Cargo.toml b/heed/Cargo.toml index 2cf4ad0c..38d6fd2e 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -35,11 +35,11 @@ url = "2.3.1" default = ["serde", "serde-bincode", "serde-json"] serde = ["bitflags/serde", "dep:serde"] -# The #MDB_NOTLS flag is automatically set on Env opening and -# RoTxn implements the Send trait. This allows the user to move -# a RoTxn between threads as read transactions will no more use -# thread local storage and will tie reader locktable slots to -# #MDB_txn objects instead of to threads. +# The #MDB_NOTLS flag is automatically set on Env opening, +# RoTxn and RoCursors implements the Send trait. This allows the +# user to move RoTxns and RoCursors between threads as read transactions +# will no more use thread local storage and will tie reader locktable +# slots to #MDB_txn objects instead of to threads. # # According to the LMDB documentation, when this feature is not enabled: # A thread can only use one transaction at a time, plus any child diff --git a/heed/src/database.rs b/heed/src/database.rs index 851b78a8..71cccc23 100644 --- a/heed/src/database.rs +++ b/heed/src/database.rs @@ -367,6 +367,9 @@ impl Database { /// Returns an iterator over all of the values of a single key. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; @@ -960,6 +963,9 @@ impl Database { /// Return a lexicographically ordered iterator of all key-value pairs in this database. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; @@ -1056,6 +1062,9 @@ impl Database { /// Return a reversed lexicographically ordered iterator of all key-value pairs in this database. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; @@ -1156,6 +1165,9 @@ impl Database { /// /// Comparisons are made by using the bytes representation of the key. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; @@ -1325,6 +1337,9 @@ impl Database { /// /// Comparisons are made by using the bytes representation of the key. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; @@ -1494,6 +1509,9 @@ impl Database { /// /// Comparisons are made by using the bytes representation of the key. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; @@ -1621,6 +1639,9 @@ impl Database { /// /// Comparisons are made by using the bytes representation of the key. /// + /// You can make this iterator `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ``` /// # use std::fs; /// # use std::path::Path; diff --git a/heed/src/env.rs b/heed/src/env.rs index c0309a09..72aa5ad7 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -658,6 +658,9 @@ impl Env { /// Create a transaction with read-only access for use with the environment. /// + /// You can make this transaction `Send`able between threads by + /// using the `read-txn-no-tls` crate feature. + /// /// ## LMDB Limitations /// /// It's possible to have multiple read transactions in the same environment diff --git a/heed/src/iterator/iter.rs b/heed/src/iterator/iter.rs index 5c67bb0b..9aacffb6 100644 --- a/heed/src/iterator/iter.rs +++ b/heed/src/iterator/iter.rs @@ -206,6 +206,9 @@ impl fmt::Debug for RoIter<'_, KC, DC, IM> { } } +#[cfg(feature = "read-txn-no-tls")] +unsafe impl Send for RoIter<'_, KC, DC, IM> {} + /// A read-write iterator structure. pub struct RwIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> { cursor: RwCursor<'txn>, @@ -552,6 +555,9 @@ impl fmt::Debug for RoRevIter<'_, KC, DC, IM> { } } +#[cfg(feature = "read-txn-no-tls")] +unsafe impl Send for RoRevIter<'_, KC, DC, IM> {} + /// A reverse read-write iterator structure. pub struct RwRevIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> { cursor: RwCursor<'txn>, diff --git a/heed/src/iterator/prefix.rs b/heed/src/iterator/prefix.rs index ecbef9a0..f0f2cc5a 100644 --- a/heed/src/iterator/prefix.rs +++ b/heed/src/iterator/prefix.rs @@ -200,6 +200,9 @@ impl fmt::Debug for RoPrefix<'_, KC, DC, C, IM> { } } +#[cfg(feature = "read-txn-no-tls")] +unsafe impl Send for RoPrefix<'_, KC, DC, IM> {} + /// A read-write prefix iterator structure. pub struct RwPrefix<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { cursor: RwCursor<'txn>, @@ -587,6 +590,9 @@ impl fmt::Debug for RoRevPrefix<'_, KC, DC, C, IM> { } } +#[cfg(feature = "read-txn-no-tls")] +unsafe impl Send for RoRevPrefix<'_, KC, DC, IM> {} + /// A reverse read-write prefix iterator structure. pub struct RwRevPrefix<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> { cursor: RwCursor<'txn>, diff --git a/heed/src/iterator/range.rs b/heed/src/iterator/range.rs index 45f8cb08..b2f89749 100644 --- a/heed/src/iterator/range.rs +++ b/heed/src/iterator/range.rs @@ -198,6 +198,9 @@ impl fmt::Debug for RoRange<'_, KC, DC, IM> { } } +#[cfg(feature = "read-txn-no-tls")] +unsafe impl Send for RoRange<'_, KC, DC, IM> {} + /// A read-write range iterator structure. pub struct RwRange<'txn, KC, DC, IM = MoveThroughDuplicateValues> { cursor: RwCursor<'txn>, @@ -632,6 +635,9 @@ impl fmt::Debug for RoRevRange<'_, KC, DC, IM> { } } +#[cfg(feature = "read-txn-no-tls")] +unsafe impl Send for RoRevRange<'_, KC, DC, IM> {} + /// A reverse read-write range iterator structure. pub struct RwRevRange<'txn, KC, DC, IM = MoveThroughDuplicateValues> { cursor: RwCursor<'txn>,