Lucene.Net.Core.Util.Counter: Changed back to original implementation that uses 
AtomicInt64 rather than Interlocked


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/cccf0c5a
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/cccf0c5a
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/cccf0c5a

Branch: refs/heads/api-work
Commit: cccf0c5aebfd3c13c03d0aa5e72423f008bff1a7
Parents: d7c5af9
Author: Shad Storhaug <[email protected]>
Authored: Thu Mar 23 23:01:02 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Thu Mar 23 23:01:02 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/Counter.cs | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cccf0c5a/src/Lucene.Net.Core/Util/Counter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Counter.cs 
b/src/Lucene.Net.Core/Util/Counter.cs
index ef44474..099b8ee 100644
--- a/src/Lucene.Net.Core/Util/Counter.cs
+++ b/src/Lucene.Net.Core/Util/Counter.cs
@@ -1,4 +1,4 @@
-using System.Threading;
+using Lucene.Net.Support;
 
 namespace Lucene.Net.Util
 {
@@ -58,7 +58,7 @@ namespace Lucene.Net.Util
         /// <returns> a new counter. </returns>
         public static Counter NewCounter(bool threadSafe)
         {
-            return threadSafe ? (Counter)new AtomicCounter() : (Counter)new 
SerialCounter();
+            return threadSafe ? (Counter)new AtomicCounter() : new 
SerialCounter();
         }
 
         private sealed class SerialCounter : Counter
@@ -78,24 +78,16 @@ namespace Lucene.Net.Util
 
         private sealed class AtomicCounter : Counter
         {
-            //internal readonly AtomicLong Count = new AtomicLong();
-            private long count;
+            private readonly AtomicInt64 count = new AtomicInt64();
 
             public override long AddAndGet(long delta)
             {
-                return Interlocked.Add(ref count, delta);
+                return count.AddAndGet(delta);
             }
 
             public override long Get()
             {
-                //LUCENE TO-DO read operations atomic in 64 bit
-                /*if (IntPtr.Size == 4)
-                {
-                    long Count_ = 0;
-                    Interlocked.Exchange(ref Count_, (long)Count);
-                    return (int)Interlocked.Read(ref Count_);
-                }*/
-                return count;
+                return count.Get();
             }
         }
     }

Reply via email to