public void Release(IProtoBufConnection connection)
 {
     ReservedLock.EnterWriteLock();
     AvailableLock.EnterWriteLock();
     ReservedConnections.Remove(connection);
     AvailableConnections.Enqueue(connection);
     AvailableLock.ExitWriteLock();
     ReservedLock.ExitWriteLock();
 }
        public IConnectionHandle Acquire()
        {
            IProtoBufConnection connection = null;

            do
            {
                AvailableLock.EnterUpgradeableReadLock();
                if (AvailableConnections.Count > 0)
                {
                    AvailableLock.EnterWriteLock();
                    connection = AvailableConnections.Dequeue();
                    AvailableLock.ExitWriteLock();
                }
                AvailableLock.ExitUpgradeableReadLock();
                if (connection == null)
                {
                    continue;
                }
                ReservedLock.EnterWriteLock();
                ReservedConnections.Add(connection);
                ReservedLock.ExitWriteLock();
            } while (connection == null);
            return(new PooledConnectionHandle(this, connection));
        }