示例#1
0
        public void Release(IProtoBufConnection connection)
        {
            IProtoBufConnection removed;

            ReservedConnections.TryRemove(connection, out removed);
            AvailableConnections.Enqueue(connection);
        }
 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));
        }