66// copied, modified, or distributed except according to those terms.
77
88use cell:: { Cell , UnsafeCell } ;
9- use mem;
109use ptr;
1110use sync:: atomic:: { AtomicPtr , AtomicUsize , Ordering , ATOMIC_USIZE_INIT } ;
1211use thread:: LocalKey ;
@@ -37,21 +36,15 @@ impl HashTable {
3736 fn new ( num_threads : usize , prev : * const HashTable ) -> Box < HashTable > {
3837 let new_size = ( num_threads * LOAD_FACTOR ) . next_power_of_two ( ) ;
3938 let hash_bits = 0usize . leading_zeros ( ) - new_size. leading_zeros ( ) - 1 ;
40- let bucket = Bucket {
41- mutex : WordLock :: new ( ) ,
42- queue_head : Cell :: new ( ptr:: null ( ) ) ,
43- queue_tail : Cell :: new ( ptr:: null ( ) ) ,
44- fair_timeout : UnsafeCell :: new ( FairTimeout :: new ( ) ) ,
45- _padding : unsafe { mem:: uninitialized ( ) } ,
46- } ;
4739 Box :: new ( HashTable {
48- entries : vec ! [ bucket ; new_size] . into_boxed_slice ( ) ,
49- hash_bits : hash_bits ,
40+ entries : vec ! [ Bucket :: new ( ) ; new_size] . into_boxed_slice ( ) ,
41+ hash_bits,
5042 _prev : prev,
5143 } )
5244 }
5345}
5446
47+ #[ repr( align( 64 ) ) ]
5548struct Bucket {
5649 // Lock protecting the queue
5750 mutex : WordLock ,
@@ -62,26 +55,26 @@ struct Bucket {
6255
6356 // Next time at which point be_fair should be set
6457 fair_timeout : UnsafeCell < FairTimeout > ,
65-
66- // Padding to avoid false sharing between buckets. Ideally we would just
67- // align the bucket structure to 64 bytes, but Rust doesn't support that
68- // yet.
69- _padding : [ u8 ; 64 ] ,
7058}
7159
72- // Implementation of Clone for Bucket, needed to make vec![] work
73- impl Clone for Bucket {
74- fn clone ( & self ) -> Bucket {
75- Bucket {
60+ impl Bucket {
61+ pub fn new ( ) -> Self {
62+ Self {
7663 mutex : WordLock :: new ( ) ,
7764 queue_head : Cell :: new ( ptr:: null ( ) ) ,
7865 queue_tail : Cell :: new ( ptr:: null ( ) ) ,
7966 fair_timeout : UnsafeCell :: new ( FairTimeout :: new ( ) ) ,
80- _padding : unsafe { mem:: uninitialized ( ) } ,
8167 }
8268 }
8369}
8470
71+ // Implementation of Clone for Bucket, needed to make vec![] work
72+ impl Clone for Bucket {
73+ fn clone ( & self ) -> Self {
74+ Self :: new ( )
75+ }
76+ }
77+
8578struct FairTimeout {
8679 // Next time at which point be_fair should be set
8780 timeout : Instant ,
0 commit comments