Exemple #1
0
        /// <summary>
        /// Returns an existing instance to this <see cref="LocklessInstancePoolGeneric{TInstance}"/>.
        /// </summary>
        /// <param name="item">The instance to return.</param>
        public void ReturnInstance(TInstance item)
        {
            var itemHolder = new InstanceHolder <TInstance>(item);
            InstanceHolder <TInstance> first;

            do
            {
                first           = this._firstInstance;
                itemHolder.Next = first;
            } while (!Object.ReferenceEquals(first, System.Threading.Interlocked.CompareExchange(ref this._firstInstance, itemHolder, first)));
        }
Exemple #2
0
 /// <summary>
 /// Returns an existing instance to this pool. Nothing is done if <paramref name="instance"/> is <c>null</c>.
 /// </summary>
 /// <param name="instance">The instance to return to this pool.</param>
 public void ReturnInstance(TInstance instance)
 {
     if (instance != null)
     {
         InstanceHolder <TInstance> first;
         var instanceInfo = new InstanceHolder <TInstance>(instance);
         do
         {
             first             = this._firstInstance;
             instanceInfo.Next = first;
         } while (!Object.ReferenceEquals(first, Interlocked.CompareExchange(ref this._firstInstance, instanceInfo, first)));
     }
 }
Exemple #3
0
 /// <summary>
 /// Creates new instance of <see cref="LocklessInstancePoolForClasses{TInstance}"/>.
 /// </summary>
 public LocklessInstancePoolForClasses()
 {
     this._firstInstance = null;
 }