Lucene.Net.Core.Util.DoubleBarrelLRUCache: Changed back to original implementation that uses AtomicInt32 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/5e4b01a2 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/5e4b01a2 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/5e4b01a2 Branch: refs/heads/api-work Commit: 5e4b01a26f210b7d4265907ff6890347da085761 Parents: dc04c72 Author: Shad Storhaug <[email protected]> Authored: Thu Mar 23 22:45:37 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Mar 23 22:45:37 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5e4b01a2/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs b/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs index 7944090..0bd5d2e 100644 --- a/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs +++ b/src/Lucene.Net.Core/Util/DoubleBarrelLRUCache.cs @@ -1,6 +1,6 @@ +using Lucene.Net.Support; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Threading; namespace Lucene.Net.Util { @@ -46,8 +46,7 @@ namespace Lucene.Net.Util private readonly IDictionary<TKey, TValue> cache1; private readonly IDictionary<TKey, TValue> cache2; - //private readonly AtomicInteger Countdown; - private int countdown; + private readonly AtomicInt32 countdown; private volatile bool swapped; private readonly int maxSize; @@ -55,7 +54,7 @@ namespace Lucene.Net.Util public DoubleBarrelLRUCache(int maxCount) { this.maxSize = maxCount; - Interlocked.Exchange(ref countdown, maxCount); + countdown = new AtomicInt32(maxCount); cache1 = new ConcurrentDictionary<TKey, TValue>(); cache2 = new ConcurrentDictionary<TKey, TValue>(); } @@ -105,7 +104,7 @@ namespace Lucene.Net.Util } primary[key] = value; - if (Interlocked.Decrement(ref countdown) == 0) + if (countdown.DecrementAndGet() == 0) { // Time to swap @@ -122,7 +121,7 @@ namespace Lucene.Net.Util swapped = !swapped; // Third, reset countdown - Interlocked.Exchange(ref countdown, maxSize); + countdown.Set(maxSize); } } }
