Skip to content

Commit

Permalink
[bcl]Switch BlockingCollection to use SequentialLayot to make sure it…
Browse files Browse the repository at this point in the history
…s longs are 8 bytes aligned everywhere.
  • Loading branch information
kumpera committed Sep 3, 2013
1 parent 7e2c766 commit 0923ad6
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -37,14 +37,24 @@ namespace System.Collections.Concurrent
[ComVisible (false)]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
[StructLayout (LayoutKind.Sequential, Pack = 8)]
public class BlockingCollection<T> : IEnumerable<T>, ICollection, IEnumerable, IDisposable
{
const int spinCount = 5;

readonly IProducerConsumerCollection<T> underlyingColl;
readonly int upperBound;

/* These events are used solely for the purpose of having an optimized sleep cycle when
* the BlockingCollection have to wait on an external event (Add or Remove for instance)
*/
ManualResetEventSlim mreAdd = new ManualResetEventSlim (true);
ManualResetEventSlim mreRemove = new ManualResetEventSlim (true);
AtomicBoolean isComplete;

readonly int upperBound;

int manualPadding;

long completeId;

/* The whole idea of the collection is to use these two long values in a transactional
Expand All @@ -57,11 +67,6 @@ public class BlockingCollection<T> : IEnumerable<T>, ICollection, IEnumerable, I
long addId = long.MinValue;
long removeId = long.MinValue;

/* These events are used solely for the purpose of having an optimized sleep cycle when
* the BlockingCollection have to wait on an external event (Add or Remove for instance)
*/
ManualResetEventSlim mreAdd = new ManualResetEventSlim (true);
ManualResetEventSlim mreRemove = new ManualResetEventSlim (true);

/* For time based operations, we share this instance of Stopwatch and base calculation
on a time offset at each of these method call */
Expand Down

0 comments on commit 0923ad6

Please sign in to comment.