Skip to content

Commit

Permalink
add safety comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 17, 2024
1 parent 89a25ad commit ff32bbc
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,24 @@ struct ThreadLocalReadTransactionsContainer(UnsafeCell<SmallVec<[RoTransaction<'

impl ThreadLocalReadTransactionsContainer {
unsafe fn pop(&self) -> Option<RoTransaction<'static>> {
// Safety: Access only happens via `push` and `pop`, and
// `ThreadLocalReadTransactionsContainer` is not `Sync`, so we can know we can know this
// block is the only one currently reading or writing to the cell.
let vec = unsafe { &mut *self.0.get() };
vec.pop()
}

unsafe fn push(&self, tx: RoTransaction<'static>) {
// Safety: Access only happens via `push` and `pop`, and
// `ThreadLocalReadTransactionsContainer` is not `Sync`, so we can know we can know this
// block is the only one currently reading or writing to the cell.
let vec = unsafe { &mut *self.0.get() };
vec.push(tx)
}
}

// Safety: It's safe to send RoTransaction between threads, but the types don't allow that.
// Safety: It's safe to send `RoTransaction` between threads as we construct `Environment` with
// `EnvironmentFlags::NO_TLS`, but the types don't allow that.
unsafe impl Send for ThreadLocalReadTransactionsContainer {}

pub struct LmdbBackingStorage {
Expand Down

0 comments on commit ff32bbc

Please sign in to comment.