Skip to content

Commit

Permalink
add padding to prevent false sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
toffaletti authored and brson committed Oct 26, 2013
1 parent 5876e21 commit c372fa5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libstd/rt/mpmc_bounded_queue.rs
Expand Up @@ -40,10 +40,14 @@ struct Node<T> {
}

struct State<T> {
pad0: [u8, ..64],
buffer: ~[Node<T>],
mask: uint,
pad1: [u8, ..64],
enqueue_pos: AtomicUint,
pad2: [u8, ..64],
dequeue_pos: AtomicUint,
pad3: [u8, ..64],
}

struct Queue<T> {
Expand All @@ -62,10 +66,14 @@ impl<T: Send> State<T> {
Node{sequence:AtomicUint::new(i),value:None}
};
State{
pad0: [0, ..64],
buffer: buffer,
mask: capacity-1,
pad1: [0, ..64],
enqueue_pos: AtomicUint::new(0),
pad2: [0, ..64],
dequeue_pos: AtomicUint::new(0),
pad3: [0, ..64],
}
}

Expand Down

0 comments on commit c372fa5

Please sign in to comment.