Exemple #1
0
        public void Resume(HThread CurrThread)
        {
            SchedulerThread SchedThread;

            Logging.Debug($"{GetDbgThreadInfo(CurrThread)} entering ipc delay wait state.");

            lock (SchedLock)
            {
                if (!AllThreads.TryGetValue(CurrThread, out SchedThread))
                {
                    Logging.Error($"{GetDbgThreadInfo(CurrThread)} was not found on the scheduler queue!");

                    return;
                }
            }

            TryResumingExecution(SchedThread);
        }
Exemple #2
0
        private void TryResumingExecution(SchedulerThread SchedThread)
        {
            HThread Thread = SchedThread.Thread;

            lock (SchedLock)
            {
                if (ActiveProcessors.Add(Thread.ProcessorId))
                {
                    Logging.Debug($"{GetDbgThreadInfo(Thread)} resuming execution...");

                    return;
                }

                WaitingToRun[Thread.ProcessorId].Push(SchedThread);
            }

            SchedThread.WaitEvent.WaitOne();

            Logging.Debug($"{GetDbgThreadInfo(Thread)} resuming execution...");
        }
Exemple #3
0
        public void WaitForSignal(HThread Thread, int Timeout = -1)
        {
            SchedulerThread SchedThread;

            Logging.Debug($"{GetDbgThreadInfo(Thread)} entering signal wait state.");

            lock (SchedLock)
            {
                SchedThread = WaitingToRun[Thread.ProcessorId].Pop();

                if (SchedThread != null)
                {
                    RunThread(SchedThread);
                }
                else
                {
                    ActiveProcessors.Remove(Thread.ProcessorId);
                }

                if (!AllThreads.TryGetValue(Thread, out SchedThread))
                {
                    Logging.Error($"{GetDbgThreadInfo(Thread)} was not found on the scheduler queue!");

                    return;
                }
            }

            if (Timeout >= 0)
            {
                Logging.Debug($"{GetDbgThreadInfo(Thread)} has wait timeout of {Timeout}ms.");

                SchedThread.WaitEvent.WaitOne(Timeout);
            }
            else
            {
                SchedThread.WaitEvent.WaitOne();
            }

            TryResumingExecution(SchedThread);
        }
Exemple #4
0
            public SchedulerThread(HThread Thread)
            {
                this.Thread = Thread;

                WaitEvent = new AutoResetEvent(false);
            }
Exemple #5
0
 private string GetDbgThreadInfo(HThread Thread)
 {
     return($"Thread {Thread.ThreadId} (core {Thread.ProcessorId}) prio {Thread.Priority}");
 }
Exemple #6
0
        private void PutThreadToWait(HThread Thread, ThreadState State, int TimeoutMs = -1)
        {
            SchedulerThread SchedThread;

            lock (SchedLock)
            {
                if (!AllThreads.TryGetValue(Thread, out SchedThread))
                {
                    return;
                }

                if (SchedThread.Signaled && SchedThread.State == ThreadState.WaitingSignal)
                {
                    SchedThread.Signaled = false;

                    return;
                }

                ActiveProcessors.Remove(Thread.ProcessorId);

                SchedThread.State = State;

                TryRunningWaitingThead(SchedThread.Thread.ProcessorId);

                if (State == ThreadState.WaitingSignal)
                {
                    InsertSorted(SchedThread);
                }
                else
                {
                    InsertAtEnd(SchedThread);
                }
            }

            if (TimeoutMs >= 0)
            {
                Logging.Debug($"{GetDbgThreadInfo(SchedThread.Thread)} waiting with timeout of {TimeoutMs}ms.");

                SchedThread.WaitEvent.WaitOne(TimeoutMs);
            }
            else
            {
                Logging.Debug($"{GetDbgThreadInfo(SchedThread.Thread)} waiting indefinitely.");

                SchedThread.WaitEvent.WaitOne();
            }

            while (true)
            {
                lock (SchedLock)
                {
                    Logging.Debug($"Trying to run {GetDbgThreadInfo(SchedThread.Thread)}.");

                    if (!ActiveProcessors.Contains(SchedThread.Thread.ProcessorId))
                    {
                        SetThreadAsRunning(SchedThread);

                        break;
                    }
                    else
                    {
                        SchedThread.State = ThreadState.WaitingToRun;

                        Logging.Debug($"{GetDbgThreadInfo(SchedThread.Thread)} waiting to run.");
                    }
                }

                SchedThread.WaitEvent.WaitOne();
            }
        }
Exemple #7
0
        public void WaitForSignal(HThread Thread)
        {
            Logging.Debug($"{GetDbgThreadInfo(Thread)} entering signal wait state.");

            PutThreadToWait(Thread, ThreadState.WaitingSignal);
        }
Exemple #8
0
        public void WaitForSignal(HThread Thread, int TimeoutMs)
        {
            Logging.Debug($"{GetDbgThreadInfo(Thread)} entering signal wait state with timeout.");

            PutThreadToWait(Thread, ThreadState.WaitingSignal, TimeoutMs);
        }