Skip to content

Commit b0d7a3c

Browse files
committed
Get rid of _padding in Bucket
1 parent d8dbe60 commit b0d7a3c

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/libstd/sys_common/parking_lot_core/parking_lot.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// copied, modified, or distributed except according to those terms.
77

88
use cell::{Cell, UnsafeCell};
9-
use mem;
109
use ptr;
1110
use sync::atomic::{AtomicPtr, AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
1211
use 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))]
5548
struct 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+
8578
struct FairTimeout {
8679
// Next time at which point be_fair should be set
8780
timeout: Instant,

0 commit comments

Comments
 (0)