Exemplo n.º 1
0
        bool Pick(out SingleThreadedExecutor executor)
        {
            var x = Volatile.Read(ref executors);

            if (x == ShutdownPool)
            {
                executor = null;
                return(false);
            }
            int idx = n;

            executor = x[idx];
            idx++;
            n = idx == parallelism ? 0 : idx;
            return(true);
        }
        public void Start()
        {
            SingleThreadedExecutor ys = null;

            for (;;)
            {
                var xs = Volatile.Read(ref executor);
                if (xs != null)
                {
                    break;
                }
                if (ys == null)
                {
                    ys = new SingleThreadedExecutor(name + "-" + (Interlocked.Increment(ref index)));
                }
                if (Interlocked.CompareExchange(ref executor, ys, xs) == xs)
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
 public void Start()
 {
     SingleThreadedExecutor[] ys = null;;
     for (;;)
     {
         var xs = Volatile.Read(ref executors);
         if (xs != ShutdownPool)
         {
             break;
         }
         if (ys == null)
         {
             ys = new SingleThreadedExecutor[parallelism];
             for (int i = 0; i < ys.Length; i++)
             {
                 ys[i] = new SingleThreadedExecutor(name + "-" + (i + 1));
             }
         }
         if (Interlocked.CompareExchange(ref executors, ys, ShutdownPool) == ShutdownPool)
         {
             break;
         }
     }
 }
 internal SingleExecutorWorker(SingleThreadedExecutor executor, Action <SingleThreadedExecutor> onShutdown = null)
 {
     this.executor   = executor;
     this.onShutdown = onShutdown;
     this.tasks      = new HashSet <InterruptibleAction>();
 }
 internal SingleExecutorService(string name = "SingleExecutorWorker")
 {
     this.name = name;
     executor  = new SingleThreadedExecutor(name);
 }