コード例 #1
0
ファイル: KScheduler.cs プロジェクト: ianuub/Ryujinxxx
        private void SwitchTo(KThread nextThread)
        {
            KProcess currentProcess = KernelStatic.GetCurrentProcess();
            KThread  currentThread  = KernelStatic.GetCurrentThread();

            nextThread ??= _idleThread;

            if (currentThread == nextThread)
            {
                return;
            }

            long previousTicks = LastContextSwitchTime;
            long currentTicks  = PerformanceCounter.ElapsedTicks;
            long ticksDelta    = currentTicks - previousTicks;

            currentThread.AddCpuTime(ticksDelta);

            if (currentProcess != null)
            {
                currentProcess.AddCpuTime(ticksDelta);
            }

            LastContextSwitchTime = currentTicks;

            if (currentProcess != null)
            {
                _previousThread = !currentThread.TerminationRequested && currentThread.ActiveCore == _coreId ? currentThread : null;
            }
            else if (currentThread == _idleThread)
            {
                _previousThread = null;
            }

            if (nextThread.CurrentCore != _coreId)
            {
                nextThread.CurrentCore = _coreId;
            }

            _currentThread = nextThread;
        }