Exemplo n.º 1
0
 private void Cleanup()
 {
     Monitor.Enter(this);
     try
     {
         if (this._isWorkItemsQueueActive)
         {
             this._isWorkItemsQueueActive = false;
             foreach (WorkItem workItem in this._workItems)
             {
                 workItem.DisposeOfState();
             }
             this._workItems.Clear();
             while (this._waitersCount > 0)
             {
                 WorkItemsQueue.WaiterEntry waiterEntry = this.PopWaiter();
                 waiterEntry.Timeout();
             }
         }
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Exemplo n.º 2
0
 private WorkItemsQueue.WaiterEntry PopWaiter()
 {
     WorkItemsQueue.WaiterEntry nextWaiterEntry  = this._headWaiterEntry._nextWaiterEntry;
     WorkItemsQueue.WaiterEntry nextWaiterEntry2 = nextWaiterEntry._nextWaiterEntry;
     this.RemoveWaiter(nextWaiterEntry, true);
     this._headWaiterEntry._nextWaiterEntry = nextWaiterEntry2;
     if (nextWaiterEntry2 != null)
     {
         nextWaiterEntry2._prevWaiterEntry = this._headWaiterEntry;
     }
     return(nextWaiterEntry);
 }
Exemplo n.º 3
0
 public void PushWaiter(WorkItemsQueue.WaiterEntry newWaiterEntry)
 {
     this.RemoveWaiter(newWaiterEntry, false);
     if (this._headWaiterEntry._nextWaiterEntry == null)
     {
         this._headWaiterEntry._nextWaiterEntry = newWaiterEntry;
         newWaiterEntry._prevWaiterEntry        = this._headWaiterEntry;
     }
     else
     {
         WorkItemsQueue.WaiterEntry nextWaiterEntry = this._headWaiterEntry._nextWaiterEntry;
         this._headWaiterEntry._nextWaiterEntry = newWaiterEntry;
         newWaiterEntry._nextWaiterEntry        = nextWaiterEntry;
         newWaiterEntry._prevWaiterEntry        = this._headWaiterEntry;
         nextWaiterEntry._prevWaiterEntry       = newWaiterEntry;
     }
     this._waitersCount++;
 }
Exemplo n.º 4
0
        private void RemoveWaiter(WorkItemsQueue.WaiterEntry waiterEntry, bool popDecrement)
        {
            WorkItemsQueue.WaiterEntry prevWaiterEntry = waiterEntry._prevWaiterEntry;
            WorkItemsQueue.WaiterEntry nextWaiterEntry = waiterEntry._nextWaiterEntry;
            bool flag = popDecrement;

            waiterEntry._prevWaiterEntry = null;
            waiterEntry._nextWaiterEntry = null;
            if (prevWaiterEntry != null)
            {
                prevWaiterEntry._nextWaiterEntry = nextWaiterEntry;
                flag = true;
            }
            if (nextWaiterEntry != null)
            {
                nextWaiterEntry._prevWaiterEntry = prevWaiterEntry;
                flag = true;
            }
            if (flag)
            {
                this._waitersCount--;
            }
        }
Exemplo n.º 5
0
        public bool EnqueueWorkItem(WorkItem workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException("workItem", "workItem cannot be null");
            }
            bool flag = true;

            Monitor.Enter(this);
            try
            {
                this.ValidateNotDisposed();
                if (!this._isWorkItemsQueueActive)
                {
                    return(false);
                }
                while (this._waitersCount > 0)
                {
                    WorkItemsQueue.WaiterEntry waiterEntry = this.PopWaiter();
                    if (waiterEntry.Signal(workItem))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    this._workItems.Enqueue(workItem);
                }
            }
            finally
            {
                Monitor.Exit(this);
            }
            return(true);
        }