Exemplo n.º 1
0
        public void ReleaseAfterDisposed()
        {
            var counter = new ScopeCounter(Mock.Of <ILifetimeScope>());

            counter.Release();
            counter.Release();
        }
Exemplo n.º 2
0
        public void Create()
        {
            var scope   = Mock.Of <ILifetimeScope>();
            var counter = new ScopeCounter(scope);

            Assert.AreSame(scope, counter.Scope);
        }
Exemplo n.º 3
0
 /// <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)))
     {
         ;
     }
 }
Exemplo n.º 4
0
 /// <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)))
     {
         ;
     }
 }
Exemplo n.º 5
0
 /// <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;
     }
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
 /// <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);
 }
Exemplo n.º 11
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);
 }
Exemplo n.º 12
0
 /// <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);
 }
Exemplo n.º 13
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>
 /// <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);
 }
Exemplo n.º 14
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);
 }
Exemplo n.º 15
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);
 }