<Compile Include="$(BclSourcesRoot)\Internal\Runtime\Augments\EnvironmentAugments.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\Augments\RuntimeThread.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Console.cs" />
+ <Compile Include="$(BclSourcesRoot)\Internal\Padding.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Reflection\Assembly.CoreCLR.cs" />
<Win32Resource Condition="'$(GenerateNativeVersionInfo)'=='true'">$(IntermediateOutputPath)\System.Private.CoreLib.res</Win32Resource>
</PropertyGroup>
<Import Project="GenerateCompilerResponseFile.targets" />
-</Project>
\ No newline at end of file
+</Project>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+namespace Internal
+{
+
+ /// <summary>A class for common padding constants and eventually routines.</summary>
+ internal static class PaddingHelpers
+ {
+ /// <summary>A size greater than or equal to the size of the most common CPU cache lines.</summary>
+#if ARM64
+ internal const int CACHE_LINE_SIZE = 128;
+#else
+ internal const int CACHE_LINE_SIZE = 64;
+#endif
+ }
+
+ /// <summary>Padding structure used to minimize false sharing</summary>
+ [StructLayout(LayoutKind.Explicit, Size = PaddingHelpers.CACHE_LINE_SIZE - sizeof(int))]
+ internal struct PaddingFor32
+ {
+ }
+}
+
/// <summary>Padded head and tail indices, to avoid false sharing between producers and consumers.</summary>
[DebuggerDisplay("Head = {Head}, Tail = {Tail}")]
- [StructLayout(LayoutKind.Explicit, Size = 192)] // padding before/between/after fields based on typical cache line size of 64
+ [StructLayout(LayoutKind.Explicit, Size = 3*Internal.PaddingHelpers.CACHE_LINE_SIZE)] // padding before/between/after fields
internal struct PaddedHeadAndTail
{
- [FieldOffset(64)] public int Head;
- [FieldOffset(128)] public int Tail;
+ [FieldOffset(1*Internal.PaddingHelpers.CACHE_LINE_SIZE)] public int Head;
+ [FieldOffset(2*Internal.PaddingHelpers.CACHE_LINE_SIZE)] public int Tail;
}
}
private struct SegmentState
{
/// <summary>Padding to reduce false sharing between the segment's array and m_first.</summary>
- internal PaddingFor32 m_pad0;
+ internal Internal.PaddingFor32 m_pad0;
/// <summary>The index of the current head in the segment.</summary>
internal volatile int m_first;
internal int m_lastCopy; // not volatile as read and written by the producer, except for IsEmpty, and there m_lastCopy is only read after reading the volatile m_first
/// <summary>Padding to reduce false sharing between the first and last.</summary>
- internal PaddingFor32 m_pad1;
+ internal Internal.PaddingFor32 m_pad1;
/// <summary>A copy of the current head index.</summary>
internal int m_firstCopy; // not voliatle as only read and written by the consumer thread
internal volatile int m_last;
/// <summary>Padding to reduce false sharing with the last and what's after the segment.</summary>
- internal PaddingFor32 m_pad2;
+ internal Internal.PaddingFor32 m_pad2;
}
/// <summary>Debugger type proxy for a SingleProducerSingleConsumerQueue of T.</summary>
}
}
}
-
- /// <summary>A placeholder class for common padding constants and eventually routines.</summary>
- internal static class PaddingHelpers
- {
- /// <summary>A size greater than or equal to the size of the most common CPU cache lines.</summary>
- internal const int CACHE_LINE_SIZE = 128;
- }
-
- /// <summary>Padding structure used to minimize false sharing in SingleProducerSingleConsumerQueue{T}.</summary>
- [StructLayout(LayoutKind.Explicit, Size = PaddingHelpers.CACHE_LINE_SIZE - sizeof(Int32))] // Based on common case of 64-byte cache lines
- internal struct PaddingFor32
- {
- }
}
internal bool loggingEnabled;
internal readonly ConcurrentQueue<IThreadPoolWorkItem> workItems = new ConcurrentQueue<IThreadPoolWorkItem>();
- private System.Threading.Tasks.PaddingFor32 pad1;
+ private Internal.PaddingFor32 pad1;
private volatile int numOutstandingThreadRequests = 0;
- private System.Threading.Tasks.PaddingFor32 pad2;
+ private Internal.PaddingFor32 pad2;
public ThreadPoolWorkQueue()
{