Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
mscorlib cache padding for 128 byte lines
Browse files Browse the repository at this point in the history
  • Loading branch information
sdmaclea committed Jul 28, 2017
1 parent ccdd60a commit 31b21b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1111,10 +1111,10 @@ internal struct Slot

/// <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 = 384)] // padding before/between/after fields based on worst case cache line size of 128
internal struct PaddedHeadAndTail
{
[FieldOffset(64)] public int Head;
[FieldOffset(128)] public int Tail;
[FieldOffset(128)] public int Head;
[FieldOffset(256)] public int Tail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ internal static class PaddingHelpers
}

/// <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
[StructLayout(LayoutKind.Explicit, Size = PaddingHelpers.CACHE_LINE_SIZE - sizeof(Int32))]
internal struct PaddingFor32
{
}
Expand Down

0 comments on commit 31b21b2

Please sign in to comment.