Exemplo n.º 1
0
 public Pool(int capacity, Action <T> recycler)
 {
     if (recycler == null)
     {
         throw new ArgumentNullException("recycler");
     }
     _id       = RuntimeUniqueIdProdiver.GetNextId();
     _entries  = new FixedSizeQueue <T>(capacity);
     _recycler = recycler;
 }
Exemplo n.º 2
0
        public static void Leave(RuntimeUniqueIdProdiver.UniqueId id)
        {
            // Assume anything could have been set to null, start no sync operation, this could be running during DomainUnload
            var guard = _guard;

            if (guard != null)
            {
                guard.Remove(id);
            }
        }
Exemplo n.º 3
0
 public Needle(T value, ICloner <T> cloner, IEqualityComparer <T> comparer)
     : base(value)
 {
     if (ReferenceEquals(cloner, null))
     {
         throw new ArgumentNullException("cloner");
     }
     _cloner     = cloner;
     _comparer   = comparer ?? EqualityComparer <T> .Default;
     _needleLock = new NeedleLock <Thread>(Context);
     _id         = RuntimeUniqueIdProdiver.GetNextId();
 }
Exemplo n.º 4
0
            public Needle(T value, IEqualityComparer <T> comparer)
                : base(value)
            {
                _cloner = CloneHelper <T> .GetCloner();

                if (ReferenceEquals(_cloner, null))
                {
                    throw new InvalidOperationException("Unable to get a cloner for " + typeof(T));
                }
                _comparer   = comparer ?? EqualityComparer <T> .Default;
                _needleLock = new NeedleLock <Thread>(Context);
                _id         = RuntimeUniqueIdProdiver.GetNextId();
            }
Exemplo n.º 5
0
 public static bool Enter(RuntimeUniqueIdProdiver.UniqueId id)
 {
     if (_guard == null)
     {
         _guard = new HashSet <RuntimeUniqueIdProdiver.UniqueId> {
             id
         };
         return(true);
     }
     if (!_guard.Contains(id))
     {
         _guard.Add(id);
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
        public static bool Enter(RuntimeUniqueIdProdiver.UniqueId id)
        {
            // Assume anything could have been set to null, start no sync operation, this could be running during DomainUnload
            var guard = _guard;

            if (guard == null)
            {
                _guard = new HashSet <RuntimeUniqueIdProdiver.UniqueId> {
                    id
                };
                return(true);
            }
            if (!guard.Contains(id))
            {
                guard.Add(id);
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
 public static bool IsTaken(RuntimeUniqueIdProdiver.UniqueId id)
 {
     return(_guard.Contains(id));
 }
Exemplo n.º 8
0
 public Pool(int capacity)
 {
     _id       = RuntimeUniqueIdProdiver.GetNextId();
     _entries  = new FixedSizeQueue <T>(capacity);
     _recycler = GC.KeepAlive;
 }
Exemplo n.º 9
0
 public static void Leave(RuntimeUniqueIdProdiver.UniqueId id)
 {
     _guard.Remove(id);
 }