6
6
// copied, modified, or distributed except according to those terms.
7
7
8
8
use cell:: { Cell , UnsafeCell } ;
9
- use mem;
10
9
use ptr;
11
10
use sync:: atomic:: { AtomicPtr , AtomicUsize , Ordering , ATOMIC_USIZE_INIT } ;
12
11
use thread:: LocalKey ;
@@ -37,21 +36,15 @@ impl HashTable {
37
36
fn new ( num_threads : usize , prev : * const HashTable ) -> Box < HashTable > {
38
37
let new_size = ( num_threads * LOAD_FACTOR ) . next_power_of_two ( ) ;
39
38
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
- } ;
47
39
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,
50
42
_prev : prev,
51
43
} )
52
44
}
53
45
}
54
46
47
+ #[ repr( align( 64 ) ) ]
55
48
struct Bucket {
56
49
// Lock protecting the queue
57
50
mutex : WordLock ,
@@ -62,26 +55,26 @@ struct Bucket {
62
55
63
56
// Next time at which point be_fair should be set
64
57
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 ] ,
70
58
}
71
59
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 {
76
63
mutex : WordLock :: new ( ) ,
77
64
queue_head : Cell :: new ( ptr:: null ( ) ) ,
78
65
queue_tail : Cell :: new ( ptr:: null ( ) ) ,
79
66
fair_timeout : UnsafeCell :: new ( FairTimeout :: new ( ) ) ,
80
- _padding : unsafe { mem:: uninitialized ( ) } ,
81
67
}
82
68
}
83
69
}
84
70
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
+
85
78
struct FairTimeout {
86
79
// Next time at which point be_fair should be set
87
80
timeout : Instant ,
0 commit comments