public void Enqueue(IThreadPoolWorkItem callback, bool forceGlobal)
        {
            ThreadPoolWorkQueueThreadLocals threadPoolWorkQueueThreadLocals = null;

            if (!forceGlobal)
            {
                threadPoolWorkQueueThreadLocals = ThreadPoolWorkQueueThreadLocals.threadLocals;
            }
            if (this.loggingEnabled)
            {
                FrameworkEventSource.Log.ThreadPoolEnqueueWorkObject(callback);
            }
            if (threadPoolWorkQueueThreadLocals != null)
            {
                threadPoolWorkQueueThreadLocals.workStealingQueue.LocalPush(callback);
            }
            else
            {
                ThreadPoolWorkQueue.QueueSegment queueSegment = this.queueHead;
                while (!queueSegment.TryEnqueue(callback))
                {
                    Interlocked.CompareExchange <ThreadPoolWorkQueue.QueueSegment>(ref queueSegment.Next, new ThreadPoolWorkQueue.QueueSegment(), null);
                    while (queueSegment.Next != null)
                    {
                        Interlocked.CompareExchange <ThreadPoolWorkQueue.QueueSegment>(ref this.queueHead, queueSegment.Next, queueSegment);
                        queueSegment = this.queueHead;
                    }
                }
            }
            this.EnsureThreadRequested();
        }
Exemplo n.º 2
0
        public void Enqueue(IThreadPoolWorkItem callback, bool forceGlobal)
        {
            ThreadPoolWorkQueueThreadLocals queueThreadLocals = (ThreadPoolWorkQueueThreadLocals)null;

            if (!forceGlobal)
            {
                queueThreadLocals = ThreadPoolWorkQueueThreadLocals.threadLocals;
            }
            if (this.loggingEnabled)
            {
                FrameworkEventSource.Log.ThreadPoolEnqueueWorkObject((object)callback);
            }
            if (queueThreadLocals != null)
            {
                queueThreadLocals.workStealingQueue.LocalPush(callback);
            }
            else
            {
                ThreadPoolWorkQueue.QueueSegment comparand = this.queueHead;
                while (!comparand.TryEnqueue(callback))
                {
                    Interlocked.CompareExchange <ThreadPoolWorkQueue.QueueSegment>(ref comparand.Next, new ThreadPoolWorkQueue.QueueSegment(), (ThreadPoolWorkQueue.QueueSegment)null);
                    for (; comparand.Next != null; comparand = this.queueHead)
                    {
                        Interlocked.CompareExchange <ThreadPoolWorkQueue.QueueSegment>(ref this.queueHead, comparand.Next, comparand);
                    }
                }
            }
            this.EnsureThreadRequested();
        }
Exemplo n.º 3
0
        public void Dequeue(ThreadPoolWorkQueueThreadLocals tl, out IThreadPoolWorkItem callback, out bool missedSteal)
        {
            callback    = (IThreadPoolWorkItem)null;
            missedSteal = false;
            ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue1 = tl.workStealingQueue;
            workStealingQueue1.LocalPop(out callback);
            if (callback == null)
            {
                for (ThreadPoolWorkQueue.QueueSegment comparand = this.queueTail; !comparand.TryDequeue(out callback) && comparand.Next != null && comparand.IsUsedUp(); comparand = this.queueTail)
                {
                    Interlocked.CompareExchange <ThreadPoolWorkQueue.QueueSegment>(ref this.queueTail, comparand.Next, comparand);
                }
            }
            if (callback != null)
            {
                return;
            }
            ThreadPoolWorkQueue.WorkStealingQueue[] current = ThreadPoolWorkQueue.allThreadQueues.Current;
            int num = tl.random.Next(current.Length);

            for (int length = current.Length; length > 0; --length)
            {
                ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue2 = Volatile.Read <ThreadPoolWorkQueue.WorkStealingQueue>(ref current[num % current.Length]);
                if (workStealingQueue2 != null && workStealingQueue2 != workStealingQueue1 && workStealingQueue2.TrySteal(out callback, ref missedSteal))
                {
                    break;
                }
                ++num;
            }
        }
 public void Dequeue(ThreadPoolWorkQueueThreadLocals tl, out IThreadPoolWorkItem callback, out bool missedSteal)
 {
     callback    = null;
     missedSteal = false;
     ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue = tl.workStealingQueue;
     workStealingQueue.LocalPop(out callback);
     if (callback == null)
     {
         ThreadPoolWorkQueue.QueueSegment queueSegment = this.queueTail;
         while (!queueSegment.TryDequeue(out callback) && queueSegment.Next != null && queueSegment.IsUsedUp())
         {
             Interlocked.CompareExchange <ThreadPoolWorkQueue.QueueSegment>(ref this.queueTail, queueSegment.Next, queueSegment);
             queueSegment = this.queueTail;
         }
     }
     if (callback == null)
     {
         ThreadPoolWorkQueue.WorkStealingQueue[] array = ThreadPoolWorkQueue.allThreadQueues.Current;
         int num = tl.random.Next(array.Length);
         for (int i = array.Length; i > 0; i--)
         {
             ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue2 = Volatile.Read <ThreadPoolWorkQueue.WorkStealingQueue>(ref array[num % array.Length]);
             if (workStealingQueue2 != null && workStealingQueue2 != workStealingQueue && workStealingQueue2.TrySteal(out callback, ref missedSteal))
             {
                 break;
             }
             num++;
         }
     }
 }
Exemplo n.º 5
0
 internal static IEnumerable <IThreadPoolWorkItem> EnumerateQueuedWorkItems(ThreadPoolWorkQueue.WorkStealingQueue[] wsQueues, ThreadPoolWorkQueue.QueueSegment globalQueueTail)
 {
     if (wsQueues != null)
     {
         foreach (ThreadPoolWorkQueue.WorkStealingQueue iteratorVariable0 in wsQueues)
         {
             if ((iteratorVariable0 != null) && (iteratorVariable0.m_array != null))
             {
                 foreach (IThreadPoolWorkItem iteratorVariable3 in iteratorVariable0.m_array)
                 {
                     if (iteratorVariable3 != null)
                     {
                         yield return(iteratorVariable3);
                     }
                 }
             }
         }
     }
     if (globalQueueTail != null)
     {
         for (ThreadPoolWorkQueue.QueueSegment iteratorVariable4 = globalQueueTail; iteratorVariable4 != null; iteratorVariable4 = iteratorVariable4.Next)
         {
             foreach (IThreadPoolWorkItem iteratorVariable7 in iteratorVariable4.nodes)
             {
                 if (iteratorVariable7 != null)
                 {
                     yield return(iteratorVariable7);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 // Token: 0x06003CEB RID: 15595 RVA: 0x000E302D File Offset: 0x000E122D
 internal static IEnumerable <IThreadPoolWorkItem> EnumerateQueuedWorkItems(ThreadPoolWorkQueue.WorkStealingQueue[] wsQueues, ThreadPoolWorkQueue.QueueSegment globalQueueTail)
 {
     if (wsQueues != null)
     {
         foreach (ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue in wsQueues)
         {
             if (workStealingQueue != null && workStealingQueue.m_array != null)
             {
                 IThreadPoolWorkItem[] items = workStealingQueue.m_array;
                 int num;
                 for (int i = 0; i < items.Length; i = num + 1)
                 {
                     IThreadPoolWorkItem threadPoolWorkItem = items[i];
                     if (threadPoolWorkItem != null)
                     {
                         yield return(threadPoolWorkItem);
                     }
                     num = i;
                 }
                 items = null;
             }
         }
         ThreadPoolWorkQueue.WorkStealingQueue[] array = null;
     }
     if (globalQueueTail != null)
     {
         ThreadPoolWorkQueue.QueueSegment segment;
         for (segment = globalQueueTail; segment != null; segment = segment.Next)
         {
             IThreadPoolWorkItem[] items2 = segment.nodes;
             int num;
             for (int j = 0; j < items2.Length; j = num + 1)
             {
                 IThreadPoolWorkItem threadPoolWorkItem2 = items2[j];
                 if (threadPoolWorkItem2 != null)
                 {
                     yield return(threadPoolWorkItem2);
                 }
                 num = j;
             }
             items2 = null;
         }
         segment = null;
     }
     yield break;
 }
Exemplo n.º 7
0
 internal static IEnumerable <IThreadPoolWorkItem> EnumerateQueuedWorkItems(ThreadPoolWorkQueue.WorkStealingQueue[] wsQueues, ThreadPoolWorkQueue.QueueSegment globalQueueTail)
 {
     if (wsQueues != null)
     {
         ThreadPoolWorkQueue.WorkStealingQueue[] workStealingQueueArray = wsQueues;
         for (int index = 0; index < workStealingQueueArray.Length; ++index)
         {
             ThreadPoolWorkQueue.WorkStealingQueue workStealingQueue = workStealingQueueArray[index];
             if (workStealingQueue != null && workStealingQueue.m_array != null)
             {
                 IThreadPoolWorkItem[] items = workStealingQueue.m_array;
                 for (int i = 0; i < items.Length; ++i)
                 {
                     IThreadPoolWorkItem threadPoolWorkItem = items[i];
                     if (threadPoolWorkItem != null)
                     {
                         yield return(threadPoolWorkItem);
                     }
                 }
                 items = (IThreadPoolWorkItem[])null;
             }
         }
         workStealingQueueArray = (ThreadPoolWorkQueue.WorkStealingQueue[])null;
     }
     if (globalQueueTail != null)
     {
         ThreadPoolWorkQueue.QueueSegment segment;
         for (segment = globalQueueTail; segment != null; segment = segment.Next)
         {
             IThreadPoolWorkItem[] items = segment.nodes;
             for (int i = 0; i < items.Length; ++i)
             {
                 IThreadPoolWorkItem threadPoolWorkItem = items[i];
                 if (threadPoolWorkItem != null)
                 {
                     yield return(threadPoolWorkItem);
                 }
             }
             items = (IThreadPoolWorkItem[])null;
         }
         segment = (ThreadPoolWorkQueue.QueueSegment)null;
     }
 }
Exemplo n.º 8
0
        internal static IEnumerable <IThreadPoolWorkItem> EnumerateQueuedWorkItems(ThreadPoolWorkQueue.WorkStealingQueue[] wsQueues, ThreadPoolWorkQueue.QueueSegment globalQueueTail)
        {
            if (wsQueues != null)
            {
                // First, enumerate all workitems in thread-local queues.
                foreach (ThreadPoolWorkQueue.WorkStealingQueue wsq in wsQueues)
                {
                    if (wsq != null && wsq.m_array != null)
                    {
                        IThreadPoolWorkItem[] items = wsq.m_array;
                        for (int i = 0; i < items.Length; i++)
                        {
                            IThreadPoolWorkItem item = items[i];
                            if (item != null)
                            {
                                yield return(item);
                            }
                        }
                    }
                }
            }

            if (globalQueueTail != null)
            {
                // Now the global queue
                for (ThreadPoolWorkQueue.QueueSegment segment = globalQueueTail;
                     segment != null;
                     segment = segment.Next)
                {
                    IThreadPoolWorkItem[] items = segment.nodes;
                    for (int i = 0; i < items.Length; i++)
                    {
                        IThreadPoolWorkItem item = items[i];
                        if (item != null)
                        {
                            yield return(item);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
 public ThreadPoolWorkQueue()
 {
     this.queueTail      = this.queueHead = new ThreadPoolWorkQueue.QueueSegment();
     this.loggingEnabled = FrameworkEventSource.Log.IsEnabled(EventLevel.Verbose, (EventKeywords)18);
 }