예제 #1
0
        /// <inheritdoc />
        public override T Take()
        {
            IPoolContracts.Take(this);

            var result = base.Take();

            this.IncrementTakenCount();
            return(result);
        }
예제 #2
0
        /// <inheritdoc />
        public override async Task <T> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            var result = await base.TakeAsync().DontMarshallContext();

            this.IncrementTakenCount();
            return(result);
        }
예제 #3
0
        /// <inheritdoc />
        public void Give(T value)
        {
            IPoolContracts.Give(this);

            this.resetAction(value);
            if (!this.buffer.Post(value))
            {
                this.releaseAction(value);
            }
        }
예제 #4
0
        /// <inheritdoc />
        public override Task <T> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            T value;

            if (this.TryTake(out value))
            {
                return(Task.FromResult(value));
            }

            return(Task.FromResult(this.factory.Create()));
        }
예제 #5
0
        /// <inheritdoc />
        public override T Take()
        {
            IPoolContracts.Take(this);

            T value;

            if (this.TryTake(out value))
            {
                return(value);
            }

            return(this.factory.Create());
        }
예제 #6
0
        /// <inheritdoc />
        public override async Task <T> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            T value;

            if (this.TryTake(out value))
            {
                return(value);
            }

            return(await this.factory.CreateAsync().DontMarshallContext());
        }
예제 #7
0
        /// <inheritdoc />
        public override bool TryTake(out T value)
        {
            IPoolContracts.TryTake(this);

            if (base.TryTake(out value))
            {
                this.IncrementTakenCount();
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #8
0
        /// <inheritdoc />
        public override void Give(T value)
        {
            IPoolContracts.Give(this);

            base.Give(value);
            this.givenCountChanged.OnNext(this.givenCount.Increment());

            long onLoan;

            if (this.onLoanCount.TryDecrementClampLower(0, out onLoan))
            {
                this.onLoanCountChanged.OnNext(onLoan);
            }
        }
        /// <inheritdoc />
        public override async Task <T> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            T value;

            if (this.TryTake(out value))
            {
                return(value);
            }

            if (this.countLeft?.TryDecrementClampLower(0) ?? true)
            {
                return(this.factory.Create());
            }

            return(await this.Pool.TakeAsync().DontMarshallContext());
        }
        /// <inheritdoc />
        public override T Take()
        {
            IPoolContracts.Take(this);

            T value;

            if (this.TryTake(out value))
            {
                return(value);
            }

            if (this.countLeft?.TryDecrementClampLower(0) ?? true)
            {
                return(this.factory.Create());
            }

            return(this.Pool.Take());
        }
        /// <inheritdoc />
        public TValue Take()
        {
            IPoolContracts.Take(this);

            TValue value;

            if (this.TryTake(out value))
            {
                return(value);
            }
            else
            {
                this.awaitingTokensCount.Increment();
                try
                {
                    return(this.pool.Take());
                }
                finally
                {
                    this.awaitingTokensCount.Decrement();
                }
            }
        }
        /// <inheritdoc />
        public bool TryTake(out TValue value)
        {
            IPoolContracts.TryTake(this);

            while (true)
            {
                if (this.pool.TryTake(out value))
                {
                    return(true);
                }
                else
                {
                    // unable to TryTake from the pool so try disposing a token
                    // to release a value back to the pool
                    if (!this.stash.TryExpireToken())
                    {
                        // unable to release any more values back to the pool
                        // so TryTake can't succeed
                        return(false);
                    }
                }
            }
        }
        /// <inheritdoc />
        public async Task <TValue> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            TValue value;

            if (this.TryTake(out value))
            {
                return(value);
            }
            else
            {
                this.awaitingTokensCount.Increment();
                try
                {
                    return(await this.pool.TakeAsync().DontMarshallContext());
                }
                finally
                {
                    this.awaitingTokensCount.Decrement();
                }
            }
        }
        /// <inheritdoc />
        public virtual void Give(T value)
        {
            IPoolContracts.Give(this);

            this.Pool.Give(value);
        }
        /// <inheritdoc />
        public virtual Task <T> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            return(this.Pool.TakeAsync());
        }
        /// <inheritdoc />
        public virtual T Take()
        {
            IPoolContracts.Take(this);

            return(this.Pool.Take());
        }
        /// <inheritdoc />
        public virtual bool TryTake(out T value)
        {
            IPoolContracts.TryTake(this);

            return(this.Pool.TryTake(out value));
        }
예제 #18
0
        /// <inheritdoc />
        public Task <T> TakeAsync()
        {
            IPoolContracts.TakeAsync(this);

            return(this.buffer.ReceiveAsync());
        }
예제 #19
0
        /// <inheritdoc />
        public T Take()
        {
            IPoolContracts.Take(this);

            return(this.buffer.Receive());
        }
예제 #20
0
        /// <inheritdoc />
        public bool TryTake(out T value)
        {
            IPoolContracts.TryTake(this);

            return(this.buffer.TryReceive(out value));
        }
        /// <inheritdoc />
        public void Give(TValue value)
        {
            IPoolContracts.Give(this);

            this.pool.Give(value);
        }