Repository: lucenenet Updated Branches: refs/heads/api-work d51ee100b -> 6a6b7a42c
BUG: Lucene.Net.Core.Util.RefCount: Reverted back to original implementation Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/6a6b7a42 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/6a6b7a42 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/6a6b7a42 Branch: refs/heads/api-work Commit: 6a6b7a42cda8795f69333da6a5318b03a4e4a3bc Parents: d51ee10 Author: Shad Storhaug <[email protected]> Authored: Thu Mar 23 20:39:25 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Mar 23 20:39:25 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Util/RefCount.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6a6b7a42/src/Lucene.Net.Core/Util/RefCount.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/RefCount.cs b/src/Lucene.Net.Core/Util/RefCount.cs index 0365a98..e33c70b 100644 --- a/src/Lucene.Net.Core/Util/RefCount.cs +++ b/src/Lucene.Net.Core/Util/RefCount.cs @@ -1,5 +1,5 @@ +using Lucene.Net.Support; using System; -using System.Threading; namespace Lucene.Net.Util { @@ -22,12 +22,11 @@ namespace Lucene.Net.Util /// <summary> /// Manages reference counting for a given object. Extensions can override - /// <seealso cref="#release()"/> to do custom logic when reference counting hits 0. + /// <see cref="Release()"/> to do custom logic when reference counting hits 0. /// </summary> public class RefCount<T> { - //private readonly AtomicInteger refCount = new AtomicInteger(1); - private int refCount = 1; + private readonly AtomicInt32 refCount = new AtomicInt32(1); protected internal readonly T m_object; @@ -47,11 +46,11 @@ namespace Lucene.Net.Util /// <summary> /// Decrements the reference counting of this object. When reference counting - /// hits 0, calls <seealso cref="#release()"/>. + /// hits 0, calls <see cref="Release()"/>. /// </summary> public void DecRef() { - int rc = Interlocked.Decrement(ref refCount); + int rc = refCount.DecrementAndGet(); if (rc == 0) { bool success = false; @@ -65,13 +64,13 @@ namespace Lucene.Net.Util if (!success) { // Put reference back on failure - Interlocked.Increment(ref refCount); + refCount.IncrementAndGet(); } } } else if (rc < 0) { - throw new InvalidOperationException("too many decRef calls: refCount is " + rc + " after decrement"); + throw new InvalidOperationException("too many DecRef() calls: refCount is " + rc + " after decrement"); } } @@ -84,23 +83,16 @@ namespace Lucene.Net.Util /// Returns the current reference count. </summary> public int GetRefCount() // LUCENENET NOTE: although this would be a good candidate for a property, doing so would cause a naming conflict { - //LUCENE TO-DO read operations atomic in 64 bit - /*if (IntPtr.Size == 4) - { - long refCount_ = 0; - Interlocked.Exchange(ref refCount_, (long)refCount); - return (int)Interlocked.Read(ref refCount_); - }*/ - return refCount; + return refCount.Get(); } /// <summary> /// Increments the reference count. Calls to this method must be matched with - /// calls to <seealso cref="#decRef()"/>. + /// calls to <see cref="DecRef()"/>. /// </summary> public void IncRef() { - Interlocked.Increment(ref refCount); + refCount.IncrementAndGet(); } } } \ No newline at end of file
