[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
public class ConcurrentBag<T> : IProducerConsumerCollection<T>, IEnumerable<T>, IEnumerable
{
- // We store hints in a long
- long hints;
+ // We store hints in an int
+ int hints;
int count;
// The container area is where bag are added foreach thread
return;
var hs = hints;
// If cas failed then we don't retry
- Interlocked.CompareExchange (ref hints, (long)(((ulong)hs) << 4 | (uint)index), (long)hs);
+ Interlocked.CompareExchange (ref hints, (int)(((uint)hs) << 4 | (uint)index), (int)hs);
}
bool TryGetHint (out int index)
{
- /* Funny little thing to know, since hints is a long (because CAS has no ulong overload),
+ /* Funny little thing to know, since hints is signed (because CAS has no uint overload),
* a shift-right operation is an arithmetic shift which might set high-order right bits
* to 1 instead of 0 if the number turns negative.
*/
var hs = hints;
index = 0;
- if (Interlocked.CompareExchange (ref hints, (long)(((ulong)hs) >> 4), hs) == hs)
+ if (Interlocked.CompareExchange (ref hints, (int)(((uint)hs) >> 4), hs) == hs)
index = (int)(hs & 0xF);
return index > 0;