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

Commit

Permalink
ConcurrentQueue 128-byte cache line (#22724)
Browse files Browse the repository at this point in the history
ConcurrentQueue 128-byte cache line
  • Loading branch information
sdmaclea authored and kouvel committed Sep 17, 2017
1 parent f77a663 commit 9c468a0
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 @@ -1112,10 +1112,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 @@ -551,7 +551,7 @@ 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))]
struct PaddingFor32
{
}
Expand Down

0 comments on commit 9c468a0

Please sign in to comment.