mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
Pad fields to cacheline size to avoid false sharing (#475)
This commit is contained in:
committed by
Carl Lerche
parent
6ba8e7621d
commit
c17ecb53e7
@@ -28,6 +28,7 @@ use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
use crossbeam_utils::cache_padded::CachePadded;
|
||||
use rand;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -40,10 +41,10 @@ pub(crate) struct Pool {
|
||||
//
|
||||
// The value of this atomic is deserialized into a `pool::State` instance.
|
||||
// See comments for that type.
|
||||
pub state: AtomicUsize,
|
||||
pub state: CachePadded<AtomicUsize>,
|
||||
|
||||
// Stack tracking sleeping workers.
|
||||
sleep_stack: worker::Stack,
|
||||
sleep_stack: CachePadded<worker::Stack>,
|
||||
|
||||
// Number of workers that haven't reached the final state of shutdown
|
||||
//
|
||||
@@ -107,8 +108,8 @@ impl Pool {
|
||||
let blocking = Blocking::new(max_blocking);
|
||||
|
||||
let ret = Pool {
|
||||
state: AtomicUsize::new(State::new().into()),
|
||||
sleep_stack: worker::Stack::new(),
|
||||
state: CachePadded::new(AtomicUsize::new(State::new().into())),
|
||||
sleep_stack: CachePadded::new(worker::Stack::new()),
|
||||
num_workers: AtomicUsize::new(0),
|
||||
workers,
|
||||
backup,
|
||||
|
||||
Reference in New Issue
Block a user