Pad fields to cacheline size to avoid false sharing (#475)

This commit is contained in:
Stjepan Glavina
2018-07-16 14:22:48 -07:00
committed by Carl Lerche
parent 6ba8e7621d
commit c17ecb53e7
6 changed files with 15 additions and 9 deletions
+3 -2
View File
@@ -8,6 +8,7 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::Ordering::{Acquire, AcqRel, Relaxed};
use crossbeam_utils::cache_padded::CachePadded;
use deque;
// TODO: None of the fields should be public
@@ -19,7 +20,7 @@ pub(crate) struct WorkerEntry {
//
// The `usize` value is deserialized to a `worker::State` instance. See
// comments on that type.
pub state: AtomicUsize,
pub state: CachePadded<AtomicUsize>,
// Next entry in the parked Trieber stack
next_sleeper: UnsafeCell<usize>,
@@ -45,7 +46,7 @@ impl WorkerEntry {
let (w, s) = deque::fifo();
WorkerEntry {
state: AtomicUsize::new(State::default().into()),
state: CachePadded::new(AtomicUsize::new(State::default().into())),
next_sleeper: UnsafeCell::new(0),
worker: w,
stealer: s,