public int DeQueue(ref _ThreadPoolWaitCallback callback)
        {
            bool lockTaken = false;
            _ThreadPoolWaitCallback callback2 = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(this.tpSync, ref lockTaken);
            }
            finally
            {
                if (lockTaken)
                {
                    _ThreadPoolWaitCallback tpHead = this.tpHead;
                    if (tpHead != null)
                    {
                        callback2   = tpHead;
                        this.tpHead = tpHead._next;
                        this.tpCount--;
                        if (this.tpCount == 0)
                        {
                            this.tpTail = null;
                            ThreadPool.ClearAppDomainRequestActive();
                        }
                    }
                    Monitor.Exit(this.tpSync);
                }
            }
            callback = callback2;
            return(this.tpCount);
        }
 public int DeQueue(ref _ThreadPoolWaitCallback callback)
 {
     bool lockTaken = false;
     _ThreadPoolWaitCallback callback2 = null;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         Monitor.Enter(this.tpSync, ref lockTaken);
     }
     finally
     {
         if (lockTaken)
         {
             _ThreadPoolWaitCallback tpHead = this.tpHead;
             if (tpHead != null)
             {
                 callback2 = tpHead;
                 this.tpHead = tpHead._next;
                 this.tpCount--;
                 if (this.tpCount == 0)
                 {
                     this.tpTail = null;
                     ThreadPool.ClearAppDomainRequestActive();
                 }
             }
             Monitor.Exit(this.tpSync);
         }
     }
     callback = callback2;
     return this.tpCount;
 }
Пример #3
0
        private static bool QueueUserWorkItemHelper(WaitCallback callBack, object state, ref StackCrawlMark stackMark, bool compressStack)
        {
            bool flag = true;

            if (callBack == null)
            {
                throw new ArgumentNullException("WaitCallback");
            }
            EnsureVMInitialized();
            if (ThreadPoolGlobals.useNewWorkerPool)
            {
                try
                {
                    return(flag);
                }
                finally
                {
                    QueueUserWorkItemCallback callback = new QueueUserWorkItemCallback(callBack, state, compressStack, ref stackMark);
                    ThreadPoolGlobals.workQueue.Enqueue(callback, true);
                    flag = true;
                }
            }
            _ThreadPoolWaitCallback tpcallBack = new _ThreadPoolWaitCallback(callBack, state, compressStack, ref stackMark);
            int num = ThreadPoolGlobals.tpQueue.EnQueue(tpcallBack);

            if (ThreadPoolGlobals.tpHosted || (num < ThreadPoolGlobals.tpWarmupCount))
            {
                return(AdjustThreadsInPool((uint)ThreadPoolGlobals.tpQueue.GetQueueCount()));
            }
            UpdateNativeTpCount((uint)ThreadPoolGlobals.tpQueue.GetQueueCount());
            return(flag);
        }
Пример #4
0
 internal static void PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
 {
     if (tpWaitCallBack._executionContext == null)
     {
         tpWaitCallBack._waitCallback(tpWaitCallBack._state);
     }
     else
     {
         ExecutionContext.Run(tpWaitCallBack._executionContext, _ccb, tpWaitCallBack, true);
     }
 }
 internal static void PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
 {
     if (tpWaitCallBack._executionContext == null)
     {
         tpWaitCallBack._waitCallback(tpWaitCallBack._state);
     }
     else
     {
         ExecutionContext.Run(tpWaitCallBack._executionContext, _ccb, tpWaitCallBack, true);
     }
 }
Пример #6
0
 private static bool QueueUserWorkItemHelper(WaitCallback callBack, Object state, ref StackCrawlMark stackMark, bool compressStack)
 {
     if (callBack != null)
     {
         _ThreadPoolWaitCallback callBackHelper = new _ThreadPoolWaitCallback(callBack, state, compressStack, ref stackMark);
         state = (Object)callBackHelper;
         return(QueueUserWorkItem(state, ref stackMark, compressStack));
     }
     else
     {
         throw new ArgumentNullException("WaitCallback");
     }
 }
Пример #7
0
        public uint EnQueue(_ThreadPoolWaitCallback tpcallBack)
        {
            uint tpCount = 0;
            bool flag    = false;
            bool flag2   = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    Monitor.Enter(this.tpSync);
                    flag = true;
                }
                catch (Exception)
                {
                }
                if (flag)
                {
                    if (this.tpCount == 0)
                    {
                        flag2 = ThreadPool.SetAppDomainRequestActive();
                    }
                    this.tpCount++;
                    tpCount = this.tpCount;
                    if (this.tpHead == null)
                    {
                        this.tpHead = tpcallBack;
                        this.tpTail = tpcallBack;
                    }
                    else
                    {
                        this.tpTail._next = tpcallBack;
                        this.tpTail       = tpcallBack;
                    }
                    Monitor.Exit(this.tpSync);
                    if (flag2)
                    {
                        ThreadPool.SetNativeTpEvent();
                    }
                }
            }
            return(tpCount);
        }
Пример #8
0
        // call back helper
        static internal void PerformWaitCallback(Object state)
        {
            _ThreadPoolWaitCallback helper = (_ThreadPoolWaitCallback)state;

            BCLDebug.Assert(helper != null, "Null state passed to PerformWaitCallback!");
            // call directly if it is an unsafe call OR EC flow is suppressed
            if (helper._executionContext == null)
            {
                WaitCallback callback = helper._waitCallback;
                callback(helper._state);
            }
            else
            {
                ExecutionContext.Run(helper._executionContext, _ccb, helper);
            }
        }
Пример #9
0
 public uint EnQueue(_ThreadPoolWaitCallback tpcallBack)
 {
     uint tpCount = 0;
     bool flag = false;
     bool flag2 = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             Monitor.Enter(this.tpSync);
             flag = true;
         }
         catch (Exception)
         {
         }
         if (flag)
         {
             if (this.tpCount == 0)
             {
                 flag2 = ThreadPool.SetAppDomainRequestActive();
             }
             this.tpCount++;
             tpCount = this.tpCount;
             if (this.tpHead == null)
             {
                 this.tpHead = tpcallBack;
                 this.tpTail = tpcallBack;
             }
             else
             {
                 this.tpTail._next = tpcallBack;
                 this.tpTail = tpcallBack;
             }
             Monitor.Exit(this.tpSync);
             if (flag2)
             {
                 ThreadPool.SetNativeTpEvent();
             }
         }
     }
     return tpCount;
 }
Пример #10
0
        internal static void PerformWaitCallback(object state)
        {
            int num = 0;
            _ThreadPoolWaitCallback tpWaitCallBack = null;
            int tickCount = Environment.TickCount;

Label_000A:
            tpWaitCallBack = ThreadPoolGlobals.tpQueue.DeQueue();
            if (tpWaitCallBack != null)
            {
                ThreadPool.CompleteThreadPoolRequest(ThreadPoolGlobals.tpQueue.GetQueueCount());
                PerformWaitCallbackInternal(tpWaitCallBack);
                num = Environment.TickCount - tickCount;
                if ((num <= ThreadPoolGlobals.tpQuantum) || !ThreadPool.ShouldReturnToVm())
                {
                    goto Label_000A;
                }
            }
        }
Пример #11
0
        private static bool QueueUserWorkItemHelper(WaitCallback callBack, object state, ref StackCrawlMark stackMark, bool compressStack)
        {
            if (callBack == null)
            {
                throw new ArgumentNullException("WaitCallback");
            }
            _ThreadPoolWaitCallback tpcallBack = new _ThreadPoolWaitCallback(callBack, state, compressStack, ref stackMark);

            if (!ThreadPoolGlobals.vmTpInitialized)
            {
                InitializeVMTp();
                ThreadPoolGlobals.vmTpInitialized = true;
            }
            uint num = ThreadPoolGlobals.tpQueue.EnQueue(tpcallBack);

            if (ThreadPoolGlobals.tpHosted || (num < ThreadPoolGlobals.tpWarmupCount))
            {
                return(AdjustThreadsInPool(ThreadPoolGlobals.tpQueue.GetQueueCount()));
            }
            UpdateNativeTpCount(ThreadPoolGlobals.tpQueue.GetQueueCount());
            return(true);
        }
Пример #12
0
        public _ThreadPoolWaitCallback DeQueue()
        {
            bool flag = false;
            _ThreadPoolWaitCallback callback = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    Monitor.Enter(this.tpSync);
                    flag = true;
                }
                catch (Exception)
                {
                }
                if (flag)
                {
                    _ThreadPoolWaitCallback tpHead = this.tpHead;
                    if (tpHead != null)
                    {
                        callback    = tpHead;
                        this.tpHead = tpHead._next;
                        this.tpCount--;
                        if (this.tpCount == 0)
                        {
                            this.tpTail = null;
                            ThreadPool.ClearAppDomainRequestActive();
                        }
                    }
                    Monitor.Exit(this.tpSync);
                }
            }
            return(callback);
        }
Пример #13
0
 public _ThreadPoolWaitCallback DeQueue()
 {
     bool flag = false;
     _ThreadPoolWaitCallback callback = null;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
             Monitor.Enter(this.tpSync);
             flag = true;
         }
         catch (Exception)
         {
         }
         if (flag)
         {
             _ThreadPoolWaitCallback tpHead = this.tpHead;
             if (tpHead != null)
             {
                 callback = tpHead;
                 this.tpHead = tpHead._next;
                 this.tpCount--;
                 if (this.tpCount == 0)
                 {
                     this.tpTail = null;
                     ThreadPool.ClearAppDomainRequestActive();
                 }
             }
             Monitor.Exit(this.tpSync);
         }
     }
     return callback;
 }
Пример #14
0
        internal static bool PerformWaitCallback()
        {
            if (ThreadPoolGlobals.useNewWorkerPool)
            {
                return(ThreadPoolWorkQueue.Dispatch());
            }
            int num = 0;
            _ThreadPoolWaitCallback callback = null;
            int tickCount = Environment.TickCount;

            do
            {
                int num3 = ThreadPoolGlobals.tpQueue.DeQueue(ref callback);
                if (callback == null)
                {
                    break;
                }
                ThreadPool.CompleteThreadPoolRequest((uint)num3);
                PerformWaitCallbackInternal(callback);
                num = Environment.TickCount - tickCount;
            }while ((num <= ThreadPoolGlobals.tpQuantum) || !ThreadPool.ShouldReturnToVm());
            return(true);
        }
 private static bool QueueUserWorkItemHelper(WaitCallback callBack, object state, ref StackCrawlMark stackMark, bool compressStack)
 {
     bool flag = true;
     if (callBack == null)
     {
         throw new ArgumentNullException("WaitCallback");
     }
     EnsureVMInitialized();
     if (ThreadPoolGlobals.useNewWorkerPool)
     {
         try
         {
             return flag;
         }
         finally
         {
             QueueUserWorkItemCallback callback = new QueueUserWorkItemCallback(callBack, state, compressStack, ref stackMark);
             ThreadPoolGlobals.workQueue.Enqueue(callback, true);
             flag = true;
         }
     }
     _ThreadPoolWaitCallback tpcallBack = new _ThreadPoolWaitCallback(callBack, state, compressStack, ref stackMark);
     int num = ThreadPoolGlobals.tpQueue.EnQueue(tpcallBack);
     if (ThreadPoolGlobals.tpHosted || (num < ThreadPoolGlobals.tpWarmupCount))
     {
         return AdjustThreadsInPool((uint) ThreadPoolGlobals.tpQueue.GetQueueCount());
     }
     UpdateNativeTpCount((uint) ThreadPoolGlobals.tpQueue.GetQueueCount());
     return flag;
 }
Пример #16
0
        static internal void WaitCallback_Context(Object state)
        {
            _ThreadPoolWaitCallback obj = (_ThreadPoolWaitCallback)state;

            obj._waitCallback(obj._state);
        }
Пример #17
0
        private static bool QueueUserWorkItemHelper(WaitCallback callBack, Object state, ref StackCrawlMark stackMark, bool compressStack )
        {
            if (callBack != null)
            {
                _ThreadPoolWaitCallback callBackHelper = new _ThreadPoolWaitCallback(callBack, state, compressStack, ref stackMark);
                state = (Object)callBackHelper;
                return QueueUserWorkItem(state, ref stackMark, compressStack);
            }
            else
            {
                throw new ArgumentNullException("WaitCallback");
            }

        }
Пример #18
0
        internal static void WaitCallback_Context(object state)
        {
            _ThreadPoolWaitCallback callback = (_ThreadPoolWaitCallback)state;

            callback._waitCallback(callback._state);
        }