示例#1
0
        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);
            }
        }
示例#2
0
 private void AddThreadToReadyList(Thread thread)
 {
     using (ProcessorCriticalSection.Acquire())
     {
         _readyThreads.AddLast(thread.ScheduleEntry);
         thread.State = ThreadState.Ready;
     }
 }
示例#3
0
        public static void RegisterDPC(LinkedListNode <DPC> dpc)
        {
            using (ProcessorCriticalSection.Acquire())
            {
                _dpcs.AddLast(dpc);
            }

            ChipControl.Default.RaiseCoreNotification();
        }
示例#4
0
        private void RemoveThreadFromReadyList(Thread thread)
        {
            using (ProcessorCriticalSection.Acquire())
            {
                _readyThreads.Remove(thread.ScheduleEntry);

                if (_runningThread == thread.ScheduleEntry)
                {
                    IRQDispatcher.RegisterDPC(_yieldDPC);
                }
            }
        }
示例#5
0
        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;
            }
        }
示例#6
0
        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();
                }
            }
        }