protected override void OnAbort()
        {
            IChannel[] channels = SnapshotChannels();
            for (int index = 0; index < channels.Length; index++)
            {
                channels[index].Abort();
            }

            ICommunicationWaiter activityWaiter = null;

            lock (ThisLock)
            {
                if (_activityWaiter != null)
                {
                    activityWaiter = _activityWaiter;
                    Interlocked.Increment(ref _activityWaiterCount);
                }
            }

            if (activityWaiter != null)
            {
                activityWaiter.Signal();
                if (Interlocked.Decrement(ref _activityWaiterCount) == 0)
                {
                    activityWaiter.Dispose();
                    _activityWaiter = null;
                }
            }

            base.OnAbort();
        }
        CommunicationWaitResult CloseCore(TimeSpan timeout, bool aborting)
        {
            ICommunicationWaiter    busyWaiter = null;
            CommunicationWaitResult result     = CommunicationWaitResult.Succeeded;

            lock (this.ThisLock)
            {
                if (this.busyCount > 0)
                {
                    if (this.busyWaiter != null)
                    {
                        if (!aborting && this.aborted)
                        {
                            return(CommunicationWaitResult.Aborted);
                        }
                        busyWaiter = this.busyWaiter;
                    }
                    else
                    {
                        busyWaiter      = new SyncCommunicationWaiter(this.ThisLock);
                        this.busyWaiter = busyWaiter;
                    }
                    Interlocked.Increment(ref busyWaiterCount);
                }
            }

            if (busyWaiter != null)
            {
                result = busyWaiter.Wait(timeout, aborting);
                if (Interlocked.Decrement(ref busyWaiterCount) == 0)
                {
                    busyWaiter.Dispose();
                    this.busyWaiter = null;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 protected virtual void OnEndClose(IAsyncResult result)
 {
     if (result is CloseCommunicationAsyncResult)
     {
         CloseCommunicationAsyncResult.End(result);
         if (Interlocked.Decrement(ref _busyWaiterCount) == 0)
         {
             _busyWaiter.Dispose();
             _busyWaiter = null;
         }
     }
     else
     {
         CompletedAsyncResult.End(result);
     }
 }
        public void DecrementActivityCount()
        {
            ICommunicationWaiter activityWaiter = null;
            bool empty = false;

            lock (ThisLock)
            {
                if (!(ActivityCount > 0))
                {
                    Fx.Assert("ServiceChannelManager.DecrementActivityCount: (this.activityCount > 0)");
                }
                if (--ActivityCount == 0)
                {
                    if (_activityWaiter != null)
                    {
                        activityWaiter = _activityWaiter;
                        Interlocked.Increment(ref _activityWaiterCount);
                    }
                    if (BusyCount == 0)
                    {
                        empty = true;
                    }
                }
            }

            if (activityWaiter != null)
            {
                activityWaiter.Signal();
                if (Interlocked.Decrement(ref _activityWaiterCount) == 0)
                {
                    activityWaiter.Dispose();
                    _activityWaiter = null;
                }
            }

            if (empty && State == LifetimeState.Opened)
            {
                OnEmpty();
            }
        }
Exemplo n.º 5
0
        protected void DecrementBusyCount()
        {
            ICommunicationWaiter busyWaiter = null;
            bool empty = false;

            lock (ThisLock)
            {
                if (BusyCount <= 0)
                {
                    throw Fx.AssertAndThrow("LifetimeManager.DecrementBusyCount: (this.busyCount > 0)");
                }
                if (--BusyCount == 0)
                {
                    if (_busyWaiter != null)
                    {
                        busyWaiter = _busyWaiter;
                        Interlocked.Increment(ref _busyWaiterCount);
                    }
                    empty = true;
                }
            }

            if (busyWaiter != null)
            {
                busyWaiter.Signal();
                if (Interlocked.Decrement(ref _busyWaiterCount) == 0)
                {
                    busyWaiter.Dispose();
                    _busyWaiter = null;
                }
            }

            if (empty && State == LifetimeState.Opened)
            {
                OnEmpty();
            }
        }