Esempio n. 1
0
        /// <summary>
        /// Releases a reference to a doorman. If the ref-count hits zero, then the doorman is
        /// returned to the pool (or is simply left for the garbage collector to cleanup if the
        /// pool is already full).
        /// </summary>
        /// <param name="doorman">The <see cref="Doorman"/>.</param>
        private static void ReleaseDoorman(Doorman doorman)
        {
            var lockTaken = false;

            try
            {
                _spinLock.Enter(ref lockTaken);

                if (--doorman.RefCount == 0)
                {
                    _keys.Remove(doorman.Key);
                    if (_pool.Count < MaxPoolSize)
                    {
                        doorman.Key = null;
                        _pool.Push(doorman);
                    }
                }
            }
            finally
            {
                if (lockTaken)
                {
                    _spinLock.Exit();
                }
            }
        }
Esempio n. 2
0
 internal Releaser(Doorman toRelease, bool writer)
 {
     _toRelease = toRelease;
     _writer    = writer;
 }