[bcl]Replace more long fields with int to make them CAS friendly on 32 bits systems.
authorRodrigo Kumpera <kumpera@gmail.com>
Wed, 4 Sep 2013 18:59:13 +0000 (14:59 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 4 Sep 2013 18:59:13 +0000 (14:59 -0400)
mcs/class/System/System.Collections.Concurrent/ConcurrentBag.cs

index 5998c061ab0302690b8f07f5328a0919759de805..5b4cbfcf1af6aaf3d4e86dc47dc0fa24ee0a28ee 100644 (file)
@@ -41,8 +41,8 @@ namespace System.Collections.Concurrent
        [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
@@ -153,19 +153,19 @@ namespace System.Collections.Concurrent
                                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;