Merge pull request #2236 from akoeplinger/add-dataflow
[mono.git] / mcs / class / System.Threading.Tasks.Dataflow / CoreFxSources / Internal / Padding.cs
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
5 //
6 // Padding.cs
7 //
8 //
9 // Helper structs for padding over CPU cache lines to avoid false sharing.
10 //
11 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
12
13 using System.Runtime.InteropServices;
14
15 namespace System.Threading.Tasks.Dataflow.Internal
16 {
17     /// <summary>A placeholder class for common padding constants and eventually routines.</summary>
18     internal static class Padding
19     {
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;
22     }
23
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
27     {
28     }
29
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
33     {
34         [FieldOffset(Padding.CACHE_LINE_SIZE)]
35         internal Int64 Value;
36     }
37 }