@@ -87,7 +87,7 @@ use core::fmt;
87
87
use core:: sync:: atomic:: { self , AtomicU64 , AtomicU8 } ;
88
88
89
89
/// The atomic ordering we use throughout the code.
90
- const ORDERING : atomic:: Ordering = atomic:: Ordering :: SeqCst ;
90
+ const ORDERING : atomic:: Ordering = atomic:: Ordering :: Relaxed ;
91
91
92
92
/// A micro cache (64 lines).
93
93
pub type MicroCache = Cache < [ AtomicU64 ; 1 ] > ;
@@ -178,7 +178,7 @@ impl<B: AsRef<[AtomicU64]>> Cache<B> {
178
178
/// ```
179
179
pub fn touch ( & self , n : usize ) {
180
180
// We OR our mask together with the bulk in order to set the bit in question.
181
- self . bulks . as_ref ( ) [ n / 64 ] . fetch_or ( 1 >> ( n % 64 ) , ORDERING ) ;
181
+ self . bulks . as_ref ( ) [ n / 64 ] . fetch_or ( 1 << ( n % 64 ) , ORDERING ) ;
182
182
}
183
183
184
184
/// Trash the n'th cache line.
@@ -204,7 +204,7 @@ impl<B: AsRef<[AtomicU64]>> Cache<B> {
204
204
/// ```
205
205
pub fn trash ( & self , n : usize ) {
206
206
// We use a mask and atomic AND in order to set the bit to zero.
207
- self . bulks . as_ref ( ) [ n / 64 ] . fetch_and ( !( 1 >> ( n % 64 ) ) , ORDERING ) ;
207
+ self . bulks . as_ref ( ) [ n / 64 ] . fetch_and ( !( 1 << ( n % 64 ) ) , ORDERING ) ;
208
208
}
209
209
210
210
/// Find the approximately least recently used cache line to replace.
@@ -278,15 +278,15 @@ impl<B: AsRef<[AtomicU64]>> Cache<B> {
278
278
/// # Example
279
279
///
280
280
/// ```rust
281
- /// let cache = plru::MicroCache;
281
+ /// let cache = plru::MicroCache::default() ;
282
282
/// cache.touch(2);
283
283
///
284
284
/// assert!(cache.is_hot(2));
285
285
/// assert!(!cache.is_hot(3));
286
286
/// ```
287
287
pub fn is_hot ( & self , n : usize ) -> bool {
288
288
// Load the bulk and mask it to find out if the bit is set.
289
- self . bulks . as_ref ( ) [ n / 64 ] . load ( ORDERING ) & ( 1 >> ( n % 64 ) ) != 0
289
+ self . bulks . as_ref ( ) [ n / 64 ] . load ( ORDERING ) & ( 1 << ( n % 64 ) ) != 0
290
290
}
291
291
}
292
292
@@ -410,7 +410,7 @@ mod tests {
410
410
fn trash_cold ( ) {
411
411
let cache = super :: SmallCache :: default ( ) ;
412
412
413
- for i in 0 ..256 {
413
+ for i in 0 ..128 {
414
414
cache. trash ( i) ;
415
415
assert ! ( !cache. is_hot( i) ) ;
416
416
}
0 commit comments