Esempio n. 1
0
        private static void Initialize()
        {
            var check = Interlocked.CompareExchange(ref _status, INT_StatusPending, INT_StatusNotReady);
            switch (check)
            {
                case INT_StatusNotReady:
                    _work = WorkContext.DefaultContext.AddWork(GCMonitor.RaiseCollected);
                    GC.KeepAlive(new GCProbe());
                    _collectedEventHandlers = new WeakDelegateSet(INT_CapacityHint, false, false, INT_MaxProbingHint);
                    Thread.VolatileWrite(ref _status, INT_StatusReady);
                    break;

                case INT_StatusPending:
                    ThreadingHelper.SpinWaitUntil(ref _status, INT_StatusReady);
                    break;
            }
        }
Esempio n. 2
0
 private void Execute(Work item)
 {
     if (item.Exclusive)
     {
         Thread.VolatileWrite(ref _waitRequest, 1);
         ThreadingHelper.SpinWaitUntil(ref _workingTotalThreadCount, 1);
         item.Execute();
         Thread.VolatileWrite(ref _waitRequest, 0);
     }
     else
     {
         item.Execute();
     }
 }
Esempio n. 3
0
 internal void ScheduleWork(Work work)
 {
     if (_work)
     {
         if (_works.Count == _works.Capacity)
         {
             ActivateDedicatedThreads();
         }
         _works.Add(work);
         if (_threads.Capacity == 0)
         {
             ThreadPool.QueueUserWorkItem(_ => DoOneWork());
         }
         else
         {
             ActivateDedicatedThreads();
         }
     }
 }