Exemplo n.º 1
0
        private void ReleaseRequest(IRequestBase request)
        {
            if (request != null)
            {
                // Synchronization of OnReleaseRequest is the
                // responsibility of the concrete implementation of request.
                request.OnReleaseRequest();
            }

            lock (_outstandingRequests)
            {
                // Remove supports the connection having been removed, so don't need extra Contains() check,
                // even though this may have been removed by Abort()
                _outstandingRequests.Remove(request);
                if (_outstandingRequests.Count == 0)
                {
                    // When we are closed or closing, _closedTcs is managed by the close logic.
                    if (!_closed && State != CommunicationState.Closing)
                    {
                        // Protect against close altering _closedTcs concurrently
                        var closedTcs = Interlocked.CompareExchange(ref _closedTcs, null, _closedTcs);
                        if (closedTcs != null)
                        {
                            closedTcs.TrySetResult(null);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void ReleaseRequest(IRequestBase request)
        {
            if (request != null)
            {
                // Synchronization of OnReleaseRequest is the
                // responsibility of the concrete implementation of request.
                request.OnReleaseRequest();
            }

            lock (outstandingRequests)
            {
                // Remove supports the connection having been removed, so don't need extra Contains() check,
                // even though this may have been removed by Abort()
                outstandingRequests.Remove(request);
                if (outstandingRequests.Count == 0)
                {
                    if (!closed && closedEvent != null)
                    {
                        closedEvent.Set();
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ReleaseRequest(IRequestBase request)
        {
            try
            {
                if (request != null)
                {
                    // Synchronization of OnReleaseRequest is the
                    // responsibility of the concrete implementation of request.
                    request.OnReleaseRequest();
                }
            }
            finally
            {
                // Setting _closedTcs needs to happen in a finally block to guarantee that we complete
                // a waiting close even if OnReleaseRequest throws
                lock (_outstandingRequests)
                {
                    _outstandingRequests.Remove(request);
                    var outstandingRequestCloseCount = Interlocked.Decrement(ref _outstandRequestCloseCount);

                    if (outstandingRequestCloseCount == 0 && _closedTcs != null)
                    {
                        // When we are closed or closing, _closedTcs is managed by the close logic.
                        if (!_closed)
                        {
                            // Protect against close altering _closedTcs concurrently by caching the value.
                            // Calling TrySetResult on an already completed TCS is a no-op
                            var closedTcs = _closedTcs;
                            if (closedTcs != null)
                            {
                                closedTcs.TrySetResult(null);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ReleaseRequest(IRequestBase request)
        {
            if (request != null)
            {
                // Synchronization of OnReleaseRequest is the
                // responsibility of the concrete implementation of request.
                request.OnReleaseRequest();
            }

            lock (_outstandingRequests)
            {
                // Remove supports the connection having been removed, so don't need extra Contains() check,
                // even though this may have been removed by Abort()
                _outstandingRequests.Remove(request);
                if (_outstandingRequests.Count == 0)
                {
                    if (!_closed && _closedTcs != null)
                    {
                        _closedTcs.TrySetResult(null);
                        _closedTcs = null;
                    }
                }
            }
        }