Пример #1
0
        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));
        }