diff options
| author | Joshua Lockerman <j@Js-MacBook-Air.home> | 2017-09-29 15:58:11 -0400 |
|---|---|---|
| committer | Joshua Lockerman <j@Js-MacBook-Air.home> | 2017-10-01 12:15:35 -0400 |
| commit | 68341a91eecb830c57779cd2423733a7395258ab (patch) | |
| tree | 851726d9a606ab4ffd49b719f741dd856e09dfd1 /src/libstd/sync/mpsc/cache_aligned.rs | |
| parent | 0e6f4cf51cd3b799fb057956f8e733d16605d09b (diff) | |
| download | rust-68341a91eecb830c57779cd2423733a7395258ab.tar.gz rust-68341a91eecb830c57779cd2423733a7395258ab.zip | |
Improve performance of spsc_queue and stream.
This commit makes two main changes. 1. It switches the spsc_queue node caching strategy from keeping a shared counter of the number of nodes in the cache to keeping a consumer only counter of the number of node eligible to be cached. 2. It separate the consumer and producers fields of spsc_queue and stream into a producer cache line and consumer cache line.
Diffstat (limited to 'src/libstd/sync/mpsc/cache_aligned.rs')
| -rw-r--r-- | src/libstd/sync/mpsc/cache_aligned.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libstd/sync/mpsc/cache_aligned.rs b/src/libstd/sync/mpsc/cache_aligned.rs new file mode 100644 index 00000000000..5af01262573 --- /dev/null +++ b/src/libstd/sync/mpsc/cache_aligned.rs @@ -0,0 +1,37 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use ops::{Deref, DerefMut}; + +#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(align(64))] +pub(super) struct Aligner; + +#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub(super) struct CacheAligned<T>(pub T, pub Aligner); + +impl<T> Deref for CacheAligned<T> { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<T> DerefMut for CacheAligned<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl<T> CacheAligned<T> { + pub(super) fn new(t: T) -> Self { + CacheAligned(t, Aligner) + } +} |
