Skip to content

Commit 7d3e965

Browse files
committed
Document the WithTls, WithoutTls and TlsUsage types and traits
1 parent d9503ba commit 7d3e965

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

heed/Cargo.toml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ url = "2.5.4"
4444
default = ["serde", "serde-bincode", "serde-json"]
4545
serde = ["bitflags/serde", "dep:serde"]
4646

47-
# The #MDB_NOTLS flag is automatically set on Env opening,
48-
# RoTxn and RoCursors implements the Send trait. This allows the
49-
# user to move RoTxns and RoCursors between threads as read transactions
50-
# will no more use thread local storage and will tie reader locktable
51-
# slots to #MDB_txn objects instead of to threads.
52-
#
53-
# According to the LMDB documentation, when this feature is not enabled:
54-
# A thread can only use one transaction at a time, plus any child
55-
# transactions. Each transaction belongs to one thread. [...]
56-
# The #MDB_NOTLS flag changes this for read-only transactions.
57-
#
58-
# And a #MDB_BAD_RSLOT error will be thrown when multiple read
59-
# transactions exists on the same thread
60-
# read-txn-no-tls = []
61-
6247
# Enable the serde en/decoders for bincode, serde_json, or rmp_serde
6348
serde-bincode = ["heed-types/serde-bincode"]
6449
serde-json = ["heed-types/serde-json"]

heed/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ use self::mdb::ffi::{from_val, into_val};
104104
pub use self::mdb::flags::{DatabaseFlags, EnvFlags, PutFlags};
105105
pub use self::reserved_space::ReservedSpace;
106106
pub use self::traits::{BoxedError, BytesDecode, BytesEncode, Comparator, LexicographicComparator};
107-
pub use self::txn::{RoTxn, RwTxn, WithTls, WithoutTls};
107+
pub use self::txn::{RoTxn, RwTxn, TlsUsage, WithTls, WithoutTls};
108108

109109
/// The underlying LMDB library version information.
110110
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]

heed/src/txn.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,32 @@ impl<T> Drop for RoTxn<'_, T> {
118118

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

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

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

0 commit comments

Comments
 (0)