Skip to content

Commit

Permalink
Document the WithTls, WithoutTls and TlsUsage types and traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Dec 15, 2024
1 parent d9503ba commit 7d3e965
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
15 changes: 0 additions & 15 deletions heed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ url = "2.5.4"
default = ["serde", "serde-bincode", "serde-json"]
serde = ["bitflags/serde", "dep:serde"]

# 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
# transactions. Each transaction belongs to one thread. [...]
# The #MDB_NOTLS flag changes this for read-only transactions.
#
# And a #MDB_BAD_RSLOT error will be thrown when multiple read
# transactions exists on the same thread
# read-txn-no-tls = []

# Enable the serde en/decoders for bincode, serde_json, or rmp_serde
serde-bincode = ["heed-types/serde-bincode"]
serde-json = ["heed-types/serde-json"]
Expand Down
2 changes: 1 addition & 1 deletion heed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ use self::mdb::ffi::{from_val, into_val};
pub use self::mdb::flags::{DatabaseFlags, EnvFlags, PutFlags};
pub use self::reserved_space::ReservedSpace;
pub use self::traits::{BoxedError, BytesDecode, BytesEncode, Comparator, LexicographicComparator};
pub use self::txn::{RoTxn, RwTxn, WithTls, WithoutTls};
pub use self::txn::{RoTxn, RwTxn, TlsUsage, WithTls, WithoutTls};

/// The underlying LMDB library version information.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
19 changes: 19 additions & 0 deletions heed/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,32 @@ impl<T> Drop for RoTxn<'_, T> {

/// Parameter defining that read transactions are opened with
/// Thread Local Storage (TLS) and cannot be sent between threads `!Send`.
///
/// When used to open transactions: A thread can only use one transaction
/// at a time, plus any child (nested) transactions. Each transaction belongs
/// to one thread. A `BadRslot` error will be thrown when multiple read
/// transactions exists on the same thread.
pub enum WithTls {}

/// Parameter defining that read transactions are opened without
/// Thread Local Storage (TLS) and are therefore `Send`.
///
/// When used to open transactions: A thread can use any number of
/// transactions at a time. Each transaction belongs to one thread but
/// can be moved in between threads (`Send`).
pub enum WithoutTls {}

/// Specifycies if Thread Local Storage (TLS) must be used when
/// opening transactions. It is often faster to open TLS-backed
/// transactions but makes them `!Send`.
///
/// The `#MDB_NOTLS` flag is set on `Env` opening, `RoTxn`s and
/// iterators implements the `Send` trait. This allows the user to
/// move `RoTxn`s and iterators between threads as read transactions
/// will no more use thread local storage and will tie reader
/// locktable slots to transaction objects instead of to threads.
pub trait TlsUsage {
/// True if TLS must be used, false otherwise.
const ENABLED: bool;
}

Expand Down

0 comments on commit 7d3e965

Please sign in to comment.