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); }
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); }
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); }
public void RemoveFirst() { _head = _head._next; if (0 == --_count) { _tail = null; } }
public void AddFirst(MsgQueueNode <T> node) { node._next = _head; _head = node; if (0 == _count++) { _tail = node; } }
public IEnumerator <T> GetEnumerator() { MsgQueueNode <T> it = _head; while (null != it) { yield return(it._value); it = it._next; } yield break; }
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); }
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); }
public void AddLast(MsgQueueNode <T> node) { if (null == _tail) { _head = node; } else { _tail._next = node; } node._next = null; _tail = node; _count++; }
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(); } }
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(); } }
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(); } } }
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(); } } }
public void Clear() { _count = 0; _head = _tail = null; }
public MsgQueue() { _count = 0; _head = _tail = null; }
public MsgQueueNode(T value) { _value = value; _next = null; }