4 using System.Threading;
6 namespace SiliconStudio.Core
13 private int counter = 1;
16 public int ReferenceCount {
get {
return counter; } }
21 int newCounter = Interlocked.Increment(ref counter);
22 if (newCounter <= 1)
throw new InvalidOperationException(FrameworkResources.AddReferenceError);
29 int newCounter = Interlocked.Decrement(ref counter);
39 Interlocked.Exchange(ref counter, newCounter + 1);
42 else if (newCounter < 0)
43 throw new InvalidOperationException(FrameworkResources.ReleaseReferenceError);
50 protected abstract void Destroy();
Base interface for all referencable objects.
virtual int Release()
Decrements the reference count of this instance. The method returns the new reference count...
Base class for a IReferencable class.
virtual int AddReference()
Increments the reference count of this instance. The method returns the new reference count...