Ejemplo n.º 1
0
        public IAsyncResult BeginEnter(TimeSpan timeout, AsyncCallback callback, object state)
        {
            AsyncSemaphore.SemaphoreWaiter semaphoreWaiter;
            bool flag;

            lock (this.SyncRoot)
            {
                if (this.count <= 0)
                {
                    flag            = false;
                    semaphoreWaiter = new AsyncSemaphore.SemaphoreWaiter(this, timeout, callback, state);
                    semaphoreWaiter.StartTimer(this.waiters.AddLast(semaphoreWaiter));
                }
                else
                {
                    flag = true;
                    AsyncSemaphore asyncSemaphore = this;
                    asyncSemaphore.count = asyncSemaphore.count - 1;
                    semaphoreWaiter      = new AsyncSemaphore.SemaphoreWaiter(this, TimeSpan.MaxValue, callback, state);
                }
            }
            if (flag)
            {
                semaphoreWaiter.Signal(true, true);
            }
            return(semaphoreWaiter);
        }
Ejemplo n.º 2
0
 public void Exit()
 {
     AsyncSemaphore.SemaphoreWaiter value = null;
     lock (this.SyncRoot)
     {
         if (this.count == this.maximumCount)
         {
             throw new SemaphoreFullException(SRCore.AsyncSemaphoreExitCalledWithoutEnter);
         }
         if (this.waiters.Count <= 0)
         {
             AsyncSemaphore asyncSemaphore = this;
             asyncSemaphore.count = asyncSemaphore.count + 1;
         }
         else
         {
             LinkedListNode <AsyncSemaphore.SemaphoreWaiter> first = this.waiters.First;
             this.waiters.Remove(first);
             value = first.Value;
         }
     }
     if (value != null)
     {
         value.Signal(false, true);
     }
 }
Ejemplo n.º 3
0
        private void HandleTimeout(AsyncSemaphore.SemaphoreWaiter waiter)
        {
            bool flag = false;

            lock (this.SyncRoot)
            {
                if (waiter.Node.List != null)
                {
                    flag = true;
                    this.waiters.Remove(waiter.Node);
                }
            }
            if (flag)
            {
                waiter.Signal(false, false);
            }
        }