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