internal void RunCoroutineFiber() { using (var platformProfiler = new Svelto.Common.PlatformProfilerMT(_name)) { while (_breakThread == false) { ThreadUtility.MemoryBarrier(); if (_newTaskRoutines.Count > 0 && false == _waitForFlush) //don't start anything while flushing { _newTaskRoutines.DequeueAllInto(_coroutines); } for (var i = 0; i < _coroutines.Count && false == _breakThread; i++) { var enumerator = _coroutines[i]; #if TASKS_PROFILER_ENABLED bool result = Profiler.TaskProfiler.MonitorUpdateDuration(enumerator, _name); #else bool result; using (platformProfiler.Sample(enumerator.ToString())) { result = enumerator.MoveNext(); } #endif if (result == false) { var disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } _coroutines.UnorderedRemoveAt(i--); } } if (_breakThread == false) { if (_interval > 0 && _waitForFlush == false) { WaitForInterval(); } if (_coroutines.Count == 0) { _waitForFlush = false; if (_newTaskRoutines.Count == 0) { _isAlive = false; if (_relaxed) { RelaxedLockingMechanism(); } else { QuickLockingMechanism(); } } ThreadUtility.MemoryBarrier(); } else { if (_isRunningTightTasks) { ThreadUtility.Yield(); } } } } if (_onThreadKilled != null) { _onThreadKilled(); } if (_mevent != null) { _mevent.Dispose(); _mevent = null; ThreadUtility.MemoryBarrier(); } } }
internal void RunCoroutineFiber() { using (var platformProfiler = new Svelto.Common.PlatformProfilerMT(_name)) { while (_breakThread == false) { ThreadUtility.MemoryBarrier(); if (_newTaskRoutines.Count > 0 && false == _waitForFlush) //don't start anything while flushing { _newTaskRoutines.DequeueAllInto(_coroutines); } IPausableTask pausableTask; bool result; for (var index = 0; index < _coroutines.Count && false == ThreadUtility.VolatileRead(ref _breakThread); ++index) #if ENABLE_PLATFORM_PROFILER using (platformProfiler.Sample(_coroutines[index].ToString())) #endif { pausableTask = _coroutines[index]; result = pausableTask.MoveNext(); if (result == false) { _coroutines.UnorderedRemoveAt(index--); } } if (ThreadUtility.VolatileRead(ref _breakThread) == false) { if (_interval > 0 && _waitForFlush == false) { WaitForInterval(); } if (_coroutines.Count == 0) { _waitForFlush = false; if (_newTaskRoutines.Count == 0) { LockingMechanism(); } ThreadUtility.MemoryBarrier(); } else { if (_isRunningTightTasks) { ThreadUtility.Wait(ref _yieldingCount, 16); } } } } if (_onThreadKilled != null) { _onThreadKilled(); } if (_mevent != null) { _mevent.Dispose(); _mevent = null; ThreadUtility.MemoryBarrier(); } } }