示例#1
0
        protected bool running_a_round(curr_strand currStrand)
        {
            currStrand.strand = this;
            while (0 != _readyQueue.Count)
            {
                if (0 != _pauseState && 0 != Interlocked.CompareExchange(ref _pauseState, 2, 1))
                {
                    currStrand.strand = null;
                    return(false);
                }
                Action stepHandler = _readyQueue.First.Value;
                _readyQueue.RemoveFirst();
                functional.catch_invoke(stepHandler);
            }
            MsgQueue <Action> waitQueue = _waitQueue;

            Monitor.Enter(this);
            if (0 != _waitQueue.Count)
            {
                _waitQueue = _readyQueue;
                Monitor.Exit(this);
                _readyQueue       = waitQueue;
                currStrand.strand = null;
                next_a_round();
            }
            else
            {
                _locked = false;
                Monitor.Exit(this);
                currStrand.strand = null;
            }
            return(true);
        }
示例#2
0
 public work_service()
 {
     _work    = 0;
     _waiting = 0;
     _runSign = true;
     _opQueue = new MsgQueue <Action>();
 }
示例#3
0
 public shared_strand()
 {
     _locked     = false;
     _pauseState = 0;
     _sysTimer   = new async_timer.steady_timer(this, false);
     _utcTimer   = new async_timer.steady_timer(this, true);
     _readyQueue = new MsgQueue <Action>();
     _waitQueue  = new MsgQueue <Action>();
     _runTask    = () => run_task();
 }