Lucene.Net.Core.Util.ClosableThreadLocal (DisposableThreadLocal): Changed back 
to original implementation that uses AtomicInt32 rather than Interlocked (fixed 
a bug in MaybePurge() in the process)


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

Branch: refs/heads/api-work
Commit: d7c5af91e627447a55cfe1716a2b6691cf9d81df
Parents: 5e4b01a
Author: Shad Storhaug <[email protected]>
Authored: Thu Mar 23 22:53:19 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Thu Mar 23 22:53:19 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/CloseableThreadLocal.cs | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d7c5af91/src/Lucene.Net.Core/Util/CloseableThreadLocal.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/CloseableThreadLocal.cs 
b/src/Lucene.Net.Core/Util/CloseableThreadLocal.cs
index 5d21cd3..239316c 100644
--- a/src/Lucene.Net.Core/Util/CloseableThreadLocal.cs
+++ b/src/Lucene.Net.Core/Util/CloseableThreadLocal.cs
@@ -66,8 +66,7 @@ namespace Lucene.Net.Util
         // purge.  After purge, we set this to
         // PURGE_MULTIPLIER * stillAliveCount.  this keeps
         // amortized cost of purging linear.
-        //private readonly AtomicInteger CountUntilPurge = new 
AtomicInteger(PURGE_MULTIPLIER);
-        private int countUntilPurge = PURGE_MULTIPLIER;
+        private readonly AtomicInt32 countUntilPurge = new 
AtomicInt32(PURGE_MULTIPLIER);
 
         protected internal virtual T InitialValue() // LUCENENET NOTE: 
Sometimes returns new instance - not a good candidate for a property
         {
@@ -110,7 +109,7 @@ namespace Lucene.Net.Util
 
         private void MaybePurge()
         {
-            if (Interlocked.Decrement(ref countUntilPurge) == 0)
+            if (countUntilPurge.GetAndDecrement() == 0)
             {
                 Purge();
             }
@@ -154,7 +153,7 @@ namespace Lucene.Net.Util
                     nextCount = 1000000;
                 }
 
-                Interlocked.Exchange(ref countUntilPurge, nextCount);
+                countUntilPurge.Set(nextCount);
             }
         }
 

Reply via email to