Backends/SiaNet.Backend.TensorSharp/RefCounted.cs
/// <summary>
/// Decrements the reference count. If the reference count reaches zero, the object is destroyed.
/// If the object has previously been destroyed, an exception is thrown.
/// </summary>
/// <exception cref="InvalidOperationException">Cannot release object - object has already been destroyed</exception>
Decrements the reference count. If the reference count reaches zero, the object is destroyed.
If the object has previously been destroyed, an exception is thrown.
Decrements the reference count . If the reference count reaches zero the object is destroyed . If the object has previously been destroyed an exception is thrown .
public void Release()
        {
            int original;
            int curRefCount;
            var spin = new SpinWait();
            while (true)
            {
                curRefCount = refCount;
                if (curRefCount == 0) throw new InvalidOperationException("Cannot release object - object has already been destroyed");
                var desiredRefCount = refCount - 1;
                original = Interlocked.CompareExchange(ref refCount, desiredRefCount, curRefCount);
                if (original == curRefCount) break;
                spin.SpinOnce();
            }
            if (refCount <= 0)
                Destroy();
        }
public void Release ( ) { int original ; int curRefCount ; var spin = new SpinWait ( ) ; while ( true ) { curRefCount = refCount ; if ( curRefCount == 0 ) throw new InvalidOperationException ( " " ) ; var desiredRefCount = refCount - 1 ; original = Interlocked . CompareExchange ( ref refCount , desiredRefCount , curRefCount ) ; if ( original == curRefCount ) break ; spin . SpinOnce ( ) ; } if ( refCount <= 0 ) Destroy ( ) ; }
Decrements the reference count.
Decrements the reference count .
Cannot release object - object has already been destroyed
Cannot release object - object has already been destroyed