コード例 #1
0
        public override bool dispatch(Action action)
        {
            curr_strand currStrand = _currStrand.Value;

            if (null != currStrand && this == currStrand.strand)
            {
                functional.catch_invoke(action);
                return(true);
            }
            else
            {
                MsgQueueNode <Action> newNode = new MsgQueueNode <Action>(action);
                Monitor.Enter(this);
                if (_locked)
                {
                    _waitQueue.AddLast(newNode);
                    Monitor.Exit(this);
                }
                else
                {
                    _locked = true;
                    _readyQueue.AddLast(newNode);
                    Monitor.Exit(this);
                    if (_checkRequired && null != currStrand && null == currStrand.strand && !_ctrl.InvokeRequired)
                    {
                        return(running_a_round(currStrand));
                    }
                    next_a_round();
                }
            }
            return(false);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: shared_strand.cs プロジェクト: qianc123/CsGo
        public override bool dispatch(Action action)
        {
            curr_strand currStrand = _currStrand.Value;

            if (null != currStrand && this == currStrand.strand)
            {
                functional.catch_invoke(action);
                return(true);
            }
            else
            {
                MsgQueueNode <Action> newNode = new MsgQueueNode <Action>(action);
                _mutex.enter();
                if (_locked)
                {
                    _waitQueue.AddLast(newNode);
                    _mutex.exit();
                }
                else
                {
                    _locked = true;
                    _readyQueue.AddLast(newNode);
                    _mutex.exit();
                    if (null != currStrand && _service == currStrand.work_service && null == currStrand.strand)
                    {
                        return(running_a_round(currStrand));
                    }
                    run_task();
                }
            }
            return(false);
        }
コード例 #4
0
        static public shared_strand default_strand()
        {
            curr_strand currStrand = _currStrand.Value;

            if (null != currStrand && null != currStrand.strand)
            {
                return(currStrand.strand);
            }
            return(_defaultStrand[mt19937.global.Next(0, _defaultStrand.Length)]);
        }
コード例 #5
0
        protected override void run_task()
        {
            curr_strand currStrand = _currStrand.Value;

            if (null == currStrand)
            {
                currStrand        = new curr_strand();
                _currStrand.Value = currStrand;
            }
            running_a_round(currStrand);
        }
コード例 #6
0
        protected virtual void run_task()
        {
            curr_strand currStrand = _currStrand.Value;

            if (null == currStrand)
            {
                currStrand        = new curr_strand(true);
                _currStrand.Value = currStrand;
            }
            running_a_round(currStrand);
        }
コード例 #7
0
        protected override void run_task()
        {
            curr_strand currStrand = _currStrand.Value;

            if (null == currStrand)
            {
                currStrand        = new curr_strand(false, _service);
                _currStrand.Value = currStrand;
            }
            running_a_round(currStrand);
            _service.release_work();
        }
コード例 #8
0
ファイル: shared_strand.cs プロジェクト: qianc123/CsGo
 protected override void make_run_task()
 {
     _runTask = delegate()
     {
         curr_strand currStrand = _currStrand.Value;
         if (null == currStrand)
         {
             currStrand        = new curr_strand();
             _currStrand.Value = currStrand;
         }
         running_a_round(currStrand);
     };
 }
コード例 #9
0
        static public shared_strand running_strand()
        {
            curr_strand currStrand = _currStrand.Value;

            return(null != currStrand ? currStrand.strand : null);
        }