1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
9 // Helper structs for padding over CPU cache lines to avoid false sharing.
11 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
13 using System.Runtime.InteropServices;
15 namespace System.Threading.Tasks.Dataflow.Internal
17 /// <summary>A placeholder class for common padding constants and eventually routines.</summary>
18 internal static class Padding
20 /// <summary>A size greater than or equal to the size of the most common CPU cache lines.</summary>
21 internal const int CACHE_LINE_SIZE = 128;
24 /// <summary>Padding structure used to minimize false sharing in SingleProducerSingleConsumerQueue{T}.</summary>
25 [StructLayout(LayoutKind.Explicit, Size = Padding.CACHE_LINE_SIZE - sizeof(Int32))] // Based on common case of 64-byte cache lines
26 internal struct PaddingForInt32
30 /// <summary>Value type that contains single Int64 value padded on both sides.</summary>
31 [StructLayout(LayoutKind.Explicit, Size = 2 * Padding.CACHE_LINE_SIZE)]
32 internal struct PaddedInt64
34 [FieldOffset(Padding.CACHE_LINE_SIZE)]