Skip to content

Commit

Permalink
fix(type-gen/key-wrapper-bounded): code generation for loom
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsonin committed Apr 27, 2024
1 parent 852963c commit 83c6cab
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/type_info_containers/key_wrapper_bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ impl<K, const CAP: usize> StaticContainer<K, CAP> {

#[inline]
#[doc(hidden)]
#[cfg(not(loom))]
pub unsafe fn key_by_offset_unchecked(&self, offset: usize) -> &K {
#[cfg(not(loom))]
let result = (*self.offset_to_orig.get_unchecked(offset).get()).assume_init_ref();
#[cfg(loom)]
let result = BorrowGuard(self.offset_to_orig.get(offset).unwrap().read().unwrap());
result
(*self.offset_to_orig.get_unchecked(offset).get()).assume_init_ref()
}

#[inline]
#[doc(hidden)]
#[cfg(loom)]
pub unsafe fn key_by_offset_unchecked(&self, offset: usize) -> RwLockReadGuard<'_, Option<K>> {
self.offset_to_orig.get(offset).unwrap().read().unwrap()
}
}

Expand Down Expand Up @@ -216,6 +220,9 @@ impl<K> Borrow<K> for BorrowGuard<'_, K> {
impl<K, const CAP: usize> KeyByOffsetProvider<K> for StaticContainer<K, CAP> {
#[inline]
unsafe fn key_by_offset_unchecked(&self, offset: usize) -> impl Borrow<K> {
StaticContainer::key_by_offset_unchecked(self, offset)
let result = StaticContainer::key_by_offset_unchecked(self, offset);
#[cfg(loom)]
let result = BorrowGuard(result);
result
}
}

0 comments on commit 83c6cab

Please sign in to comment.