@@ -289,13 +289,13 @@ impl Table {
289
289
290
290
impl < ' p , T : Slot > PageView < ' p , T > {
291
291
fn page_data ( & self ) -> & [ PageDataEntry < T > ] {
292
- let len = self . 0 . allocated . load ( Ordering :: Acquire ) ;
292
+ let len = self . 0 . allocated ( ) ;
293
293
// SAFETY: `len` is the initialized length of the page
294
294
unsafe { slice:: from_raw_parts ( self . 0 . data . cast :: < PageDataEntry < T > > ( ) . as_ptr ( ) , len) }
295
295
}
296
296
297
297
fn data ( & self ) -> & ' p [ T ] {
298
- let len = self . 0 . allocated . load ( Ordering :: Acquire ) ;
298
+ let len = self . 0 . allocated ( ) ;
299
299
// SAFETY: `len` is the initialized length of the page
300
300
unsafe { slice:: from_raw_parts ( self . 0 . data . cast :: < T > ( ) . as_ptr ( ) , len) }
301
301
}
@@ -305,7 +305,7 @@ impl<'p, T: Slot> PageView<'p, T> {
305
305
V : FnOnce ( Id ) -> T ,
306
306
{
307
307
let _guard = self . 0 . allocation_lock . lock ( ) ;
308
- let index = self . 0 . allocated . load ( Ordering :: Acquire ) ;
308
+ let index = self . 0 . allocated ( ) ;
309
309
if index >= PAGE_LEN {
310
310
return Err ( value) ;
311
311
}
@@ -320,7 +320,8 @@ impl<'p, T: Slot> PageView<'p, T> {
320
320
321
321
// Update the length (this must be done after initialization as otherwise an uninitialized
322
322
// read could occur!)
323
- self . 0 . allocated . store ( index + 1 , Ordering :: Release ) ;
323
+ // Ordering: Relaxed is fine as the `allocation_lock` establishes a happens-before relationship
324
+ self . 0 . allocated . store ( index + 1 , Ordering :: Relaxed ) ;
324
325
325
326
Ok ( id)
326
327
}
@@ -341,13 +342,20 @@ impl Page {
341
342
}
342
343
}
343
344
345
+ #[ inline]
346
+ fn allocated ( & self ) -> usize {
347
+ // Ordering: Relaxed is fine as the `allocation_lock` establishes a happens-before
348
+ // relationship
349
+ self . allocated . load ( Ordering :: Relaxed )
350
+ }
351
+
344
352
/// Retrieves the pointer for the given slot.
345
353
///
346
354
/// # Panics
347
355
///
348
356
/// If slot is out of bounds
349
357
fn get ( & self , slot : SlotIndex ) -> * mut ( ) {
350
- let len = self . allocated . load ( Ordering :: Acquire ) ;
358
+ let len = self . allocated ( ) ;
351
359
assert ! (
352
360
slot. 0 < len,
353
361
"out of bounds access `{slot:?}` (maximum slot `{len}`)"
0 commit comments