Skip to content

Commit ff32bbc

Browse files
committed
add safety comments
1 parent 89a25ad commit ff32bbc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@ struct ThreadLocalReadTransactionsContainer(UnsafeCell<SmallVec<[RoTransaction<'
6464

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

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

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

8087
pub struct LmdbBackingStorage {

0 commit comments

Comments
 (0)