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); }
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); }
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); }
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)]); }
protected override void run_task() { curr_strand currStrand = _currStrand.Value; if (null == currStrand) { currStrand = new curr_strand(); _currStrand.Value = currStrand; } running_a_round(currStrand); }
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); }
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(); }
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); }; }
static public shared_strand running_strand() { curr_strand currStrand = _currStrand.Value; return(null != currStrand ? currStrand.strand : null); }