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