Esempio n. 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);
            }
        }
Esempio n. 2
0
        private void RemoveThreadFromReadyList(Thread thread)
        {
            using (ProcessorCriticalSection.Acquire())
            {
                _readyThreads.Remove(thread.ScheduleEntry);

                if (_runningThread == thread.ScheduleEntry)
                {
                    IRQDispatcher.RegisterDPC(_yieldDPC);
                }
            }
        }
Esempio n. 3
0
        private void Start()
        {
            Debug.Assert(!_isRunning);

            _idleThread.Start();
            Debug.Assert(_readyThreads.First != null);

            _isRunning     = true;
            _runningThread = _readyThreads.First;
            IRQDispatcher.RegisterSystemIRQ(SystemIRQ.SystemTick, OnSystemTick);
            ChipControl.Default.SetupSystemTimer(TimeSlice);
            ChipControl.Default.StartSchedule(_runningThread.Value.Thread.Context);

            // Should not reach here
            while (true)
            {
                ;
            }
        }