Example #1
0
 public override bool Release()
 {
     while (true)
     {
         int currentCount = Volatile.Read(ref _referenceCount);
         if (currentCount <= 0)
         {
             ThrowHelper.ThrowInvalidOperationException_ReferenceCountZero();
         }
         if (Interlocked.CompareExchange(ref _referenceCount, currentCount - 1, currentCount) == currentCount)
         {
             if (currentCount == 1)
             {
                 OnZeroReferences();
                 return(false);
             }
             return(true);
         }
     }
 }