Ejemplo n.º 1
0
        public long run()
        {
            long count = 0;

            while (_runSign)
            {
                Monitor.Enter(_opQueue);
                if (0 != _opQueue.Count)
                {
                    MsgQueueNode <Action> firstNode = _opQueue.First;
                    _opQueue.RemoveFirst();
                    Monitor.Exit(_opQueue);
                    count++;
                    functional.catch_invoke(firstNode.Value);
                }
                else if (0 != _work)
                {
                    _waiting++;
                    Monitor.Wait(_opQueue);
                    Monitor.Exit(_opQueue);
                }
                else
                {
                    Monitor.Exit(_opQueue);
                    break;
                }
            }
            return(count);
        }
Ejemplo n.º 2
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);
                _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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void RemoveFirst()
 {
     _head = _head._next;
     if (0 == --_count)
     {
         _tail = null;
     }
 }
Ejemplo n.º 5
0
 public void AddFirst(MsgQueueNode <T> node)
 {
     node._next = _head;
     _head      = node;
     if (0 == _count++)
     {
         _tail = node;
     }
 }
Ejemplo n.º 6
0
        public IEnumerator <T> GetEnumerator()
        {
            MsgQueueNode <T> it = _head;

            while (null != it)
            {
                yield return(it._value);

                it = it._next;
            }
            yield break;
        }
Ejemplo n.º 7
0
        public void post(Action handler)
        {
            MsgQueueNode <Action> newNode = new MsgQueueNode <Action>(handler);

            Monitor.Enter(_opQueue);
            _opQueue.AddLast(newNode);
            if (0 != _waiting)
            {
                _waiting--;
                Monitor.Pulse(_opQueue);
            }
            Monitor.Exit(_opQueue);
        }
Ejemplo n.º 8
0
 public bool run_one()
 {
     Monitor.Enter(_opQueue);
     if (_runSign && 0 != _opQueue.Count)
     {
         MsgQueueNode <Action> firstNode = _opQueue.First;
         _opQueue.RemoveFirst();
         Monitor.Exit(_opQueue);
         functional.catch_invoke(firstNode.Value);
         return(true);
     }
     Monitor.Exit(_opQueue);
     return(false);
 }
Ejemplo n.º 9
0
 public void AddLast(MsgQueueNode <T> node)
 {
     if (null == _tail)
     {
         _head = node;
     }
     else
     {
         _tail._next = node;
     }
     node._next = null;
     _tail      = node;
     _count++;
 }
Ejemplo n.º 10
0
        public void post(Action action)
        {
            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);
                next_a_round();
            }
        }
Ejemplo n.º 11
0
        public void post(Action action)
        {
            MsgQueueNode <Action> newNode = new MsgQueueNode <Action>(action);

            _mutex.enter();
            if (_locked)
            {
                _waitQueue.AddLast(newNode);
                _mutex.exit();
            }
            else
            {
                _locked = true;
                _readyQueue.AddLast(newNode);
                _mutex.exit();
                run_task();
            }
        }
Ejemplo n.º 12
0
 public void last_dispatch(Action action)
 {
     if (running_in_this_thread())
     {
         _readyQueue.AddLast(action);
     }
     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);
             next_a_round();
         }
     }
 }
Ejemplo n.º 13
0
 public void last_dispatch(Action action)
 {
     if (running_in_this_thread())
     {
         _readyQueue.AddLast(action);
     }
     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();
             run_task();
         }
     }
 }
Ejemplo n.º 14
0
 public void Clear()
 {
     _count = 0;
     _head  = _tail = null;
 }
Ejemplo n.º 15
0
 public MsgQueue()
 {
     _count = 0;
     _head  = _tail = null;
 }
Ejemplo n.º 16
0
 public MsgQueueNode(T value)
 {
     _value = value;
     _next  = null;
 }