Ejemplo n.º 1
0
        public override void OnThreadBlocked(Thread thread, SchedulerTime stop)
        {
            // Assert preconditions
            VTable.Assert(thread == Thread.CurrentThread);

            if (stop != SchedulerTime.MaxValue)
            {
                // Enqueue timer so that if it expires we will notice it right a way
                EnqueueTimer(thread, stop);
            }

            // Thread is blocked now - indicate this to dispatcher. Dispatcher will make
            // make sure that thread's scheduler is aware of the blockage
            ProcessorDispatcher.SwitchContext(ThreadState.Blocked);

            // We just got unblocked and happilly running. We need to remove ourselves
            // from the timer queue if we are unblocked by signal rather than by timeout
            if (thread.UnblockedBy != WaitHandle.WaitTimeout)
            {
                // One of our buddies unblocked us - remove the time out. Before we can
                // actually assert that we were indeed unblocked by someone.
                VTable.Assert(thread.UnblockedBy != WaitHandle.UninitWait);

                // Remove a timer from the timer queue and happilly continue!
                RemoveTimer(thread);
            }
        }
Ejemplo n.º 2
0
        public override void OnThreadUnblocked(Thread thread)
        {
            // Only call this method if thread is Indeed blocked
            VTable.Assert(thread.IsBlocked);

            // Thread is ready to run: Add it to dispatcher
            ProcessorDispatcher.AddRunnableThread(thread);
        }
Ejemplo n.º 3
0
        public override void OnThreadStart(Thread thread)
        {
            // Initialize thread's affinity
            thread.Affinity = (int)ProcessorDispatcher.Affinity.All;

            // Enqueue thread into dispatcher.
            ProcessorDispatcher.AddRunnableThread(thread);
        }
Ejemplo n.º 4
0
            internal override UIntPtr Callback(UIntPtr param)
            {
                unsafe {
                    ThreadContext *newContext = (ThreadContext *)param;

                    // Switch our thread context, synchronizing with the dispatcher as necessary.
                    ProcessorDispatcher.TransferToThreadContext(ref *GetCurrentThreadContext(),
                                                                ref *newContext);

                    // Resume in the new context. Note that this call does not return.
                    newContext->threadRecord.spill.Resume();

                    return(0);
                }
            }
Ejemplo n.º 5
0
        public override void OnThreadFreezeDecrement(Thread thread)
        {
            bool shouldPutThreadOnRunnableQueue = false;

            // Assert preconditions
            DebugStub.Assert(thread.FreezeCount > 0);

            // Update threads: Freeze count
            if (thread.DecrementFreezeCounter(ref shouldPutThreadOnRunnableQueue) == 0 &&
                shouldPutThreadOnRunnableQueue)
            {
                // Thread became runnable - add it to runnable queue
                ProcessorDispatcher.AddRunnableThread(thread);
            }
        }
Ejemplo n.º 6
0
        private static void InitSchedulerTypes()
        {
            InitType(typeof(Processor));
            InitType(typeof(Scheduler));
            InitType(typeof(ProcessorDispatcher));
            // InitType(typeof(AffinityScheduler));
            InitType(typeof(MinScheduler));

            ARM_PROGRESS("Kernel!013");
            // Create scheduler before initializing processes
            scheduler = new MinScheduler();

            ARM_PROGRESS("Kernel!017");
            // Initialize processor dispatcher
            ProcessorDispatcher.StaticInitialize(scheduler);
        }
Ejemplo n.º 7
0
 public static bool IsIdleThread(int threadIdx)
 {
     return(ProcessorDispatcher.IsIdleThread(threadIdx));
 }
Ejemplo n.º 8
0
 public override void OnThreadStop(Thread thread)
 {
     // Perform a context switch: If thread is stopped it will be cleaned up, otherwise
     // it is suspended and will be cleaned up latter
     ProcessorDispatcher.SwitchContext(ThreadState.Stopped);
 }
Ejemplo n.º 9
0
 public override void OnThreadYield(Thread thread)
 {
     // Perform a context switch: If thread is runnable it will be put on a runnable queue
     // by dispatcher.
     ProcessorDispatcher.SwitchContext(ThreadState.Running);
 }