Example #1
0
        static public shared_strand top_strand()
        {
            tls_values tlsVal = _runningTls.Value;

            if (null != tlsVal && 0 != tlsVal.currStrand.Count)
            {
                return(tlsVal.currStrand.First.Value);
            }
            return(null);
        }
Example #2
0
        protected bool run_a_round1()
        {
            tls_values tlsVal = _runningTls.Value;

            if (null == tlsVal)
            {
                tlsVal            = new tls_values();
                _runningTls.Value = tlsVal;
            }
            tlsVal.currStrand.AddFirst(this);
            while (0 != _readyQueue.Count)
            {
                if (0 != _pauseState && 0 != Interlocked.CompareExchange(ref _pauseState, 2, 1))
                {
                    tlsVal.currStrand.RemoveFirst();
                    return(false);
                }
                try
                {
                    _readyQueue.First.Value.Invoke();
                }
                catch (System.Exception ec)
                {
                    MessageBox.Show(String.Format("Message:\n{0}\n{1}", ec.Message, ec.StackTrace), "shared_strand 内部未捕获的异常!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                _readyQueue.RemoveFirst();
            }
            _mutex.WaitOne();
            if (0 != _waitQueue.Count)
            {
                LinkedList <functional.func> t = _readyQueue;
                _readyQueue = _waitQueue;
                _waitQueue  = t;
                _mutex.ReleaseMutex();
                tlsVal.currStrand.RemoveFirst();
                run_task();
            }
            else
            {
                _locked = false;
                _mutex.ReleaseMutex();
                tlsVal.currStrand.RemoveFirst();
            }
            return(true);
        }
Example #3
0
        public bool running_in_this_thread()
        {
            tls_values tlsVal = _runningTls.Value;

            return(null != tlsVal && null != tlsVal.currStrand.Find(this));
        }