public void ReleaseAfterDisposed() { var counter = new ScopeCounter(Mock.Of <ILifetimeScope>()); counter.Release(); counter.Release(); }
public void Create() { var scope = Mock.Of <ILifetimeScope>(); var counter = new ScopeCounter(scope); Assert.AreSame(scope, counter.Scope); }
/// <summary>Performs a spinlock until all reference counts are zero.</summary> /// <param name="t1">The first scope to check</param> /// <param name="t2">The second scope to check</param> public static void WaitForZero(ScopeCounter t1, ScopeCounter t2) { while (!(IsZero(t1, t2))) { ; } }
/// <summary>Performs a spinlock until all reference counts are zero.</summary> /// <param name="t1">The first scope to check</param> /// <param name="t2">The second scope to check</param> /// <param name="t3">The third scope to check</param> public static void WaitForZero(ScopeCounter t1, byte t2, byte t3) { while (!(IsZero(t1, t2, t3))) { ; } }
/// <summary>Performs a spinlock until the reference count of a local scope is zero, then increments the reference count</summary> /// <param name="scope">The local scope</param> /// <returns>The updated scope</returns> public static ScopeCounter AcquireWhenZero(ScopeCounter scope) { while (!(Interlocked.CompareExchange(ref scope._count, 1, 0) == 0)) { ; } return(scope); }
public void Dispose() { if (counter != null) { counter.count--; this.counter = null; } }
private ScopeCounter Counter(Node <UriOrBlank>?scope) { var found = _scopedCounters.FirstOrDefault(x => x.Scope == scope); if (found is null) { found = new ScopeCounter(scope); _scopedCounters.Add(found); } return(found); }
public void AddAndRelease() { var scope = new Mock <ILifetimeScope>(MockBehavior.Strict); scope.Setup(_ => _.Dispose()); var counter = new ScopeCounter(scope.Object); counter.Add(); counter.Add(); counter.Release(); counter.Release(); counter.Release(); Assert.IsNull(counter.Scope); scope.VerifyAll(); }
/// <summary>Decrements the reference count of a local scope</summary> /// <param name="scope">The local scope</param> private static void ReleaseOne(ScopeCounter scope) { Interlocked.Decrement(ref scope._count); }
/// <summary>Resets the reference count of a global scope to zero</summary> /// <param name="scope">The local scope</param> public static void Reset(ScopeCounter scope) { Interlocked.Exchange(ref scope._count, 0); }
/// <summary>Increments the reference count of a local scope, then returns the updated scope</summary> /// <param name="scope">The local scope</param> /// <returns>The updated scope</returns> public static ScopeCounter Acquire(ScopeCounter scope) { Interlocked.Increment(ref scope._count); return(scope); }
/// <summary>Gets the reference count of a local scope</summary> /// <param name="scope">The local scope</param> /// <returns>The reference count of the scope</returns> public static int Get(ScopeCounter scope) { return(scope._count); }
/// <summary>Returns if the reference count of all scopes is zero</summary> /// <param name="t1">The first scope to check</param> /// <param name="t2">The second scope to check</param> /// <param name="t3">The third scope to check</param> /// <returns>True if all reference counts are zero, false otherwise</returns> public static bool IsZero(ScopeCounter t1, byte t2, byte t3) { return(Get(t1) == 0 && Get(t2) == 0 && Get(t3) == 0); }
/// <summary>Returns if the reference count of all scopes is zero</summary> /// <param name="t1">The first scope to check</param> /// <param name="t2">The second scope to check</param> /// <returns>True if all reference counts are zero, false otherwise</returns> public static bool IsZero(ScopeCounter t1, ScopeCounter t2) { return(Get(t1) == 0 && Get(t2) == 0); }
/// <summary>Increments the reference count of a local scope only if the count is zero</summary> /// <param name="scope">The local scope</param> /// <returns>True if acquired, false otherwise</returns> public static bool AcquireIfZero(ScopeCounter scope) { return(Interlocked.CompareExchange(ref scope._count, 1, 0) == 0); }