private void DelayCurrentThread(TimeSpan delay) { if (delay.Ticks < 0) { throw new ArgumentOutOfRangeException(nameof(delay)); } using (ProcessorCriticalSection.Acquire()) { // Yield if (delay.Ticks != 0) { var thread = _runningThread !; _readyThreads.Remove(thread); thread.Value.Thread.State = ThreadState.Wait; if (delay == Timeout.InfiniteTimeSpan) { _suspendedThreads.AddLast(thread); } else { var awakeTick = TickCount + (ulong)TimeSpanToTicks(delay); thread.Value.AwakeTick = awakeTick; AddThreadToDelayedList(thread); } } IRQDispatcher.RegisterDPC(_yieldDPC); } }
private void AddThreadToReadyList(Thread thread) { using (ProcessorCriticalSection.Acquire()) { _readyThreads.AddLast(thread.ScheduleEntry); thread.State = ThreadState.Ready; } }
public static void RegisterDPC(LinkedListNode <DPC> dpc) { using (ProcessorCriticalSection.Acquire()) { _dpcs.AddLast(dpc); } ChipControl.Default.RaiseCoreNotification(); }
private void RemoveThreadFromReadyList(Thread thread) { using (ProcessorCriticalSection.Acquire()) { _readyThreads.Remove(thread.ScheduleEntry); if (_runningThread == thread.ScheduleEntry) { IRQDispatcher.RegisterDPC(_yieldDPC); } } }
internal void UnDelayThread(Thread thread) { Debug.Assert(thread.State == ThreadState.Wait); using (ProcessorCriticalSection.Acquire()) { var scheduleEntry = thread.ScheduleEntry; scheduleEntry.List !.Remove(scheduleEntry); _readyThreads.AddLast(scheduleEntry); scheduleEntry.Value.Thread.State = ThreadState.Ready; } }
internal void KillThread(Thread thread) { Debug.Assert(thread._scheduler == this); using (ProcessorCriticalSection.Acquire()) { if (Interlocked.Exchange(ref thread._scheduler, null) != null) { RemoveThreadFromReadyList(thread); thread.State = ThreadState.Terminated; thread.OnKilled(); } } }