/// <summary> /// Sets the task sleeping until a given time /// </summary> /// <param name="fullTicks">Full ticks</param> /// <param name="subTicks">Sub ticks</param> /// <returns>The amount of time the task still needs to sleep (only if interrupted)</returns> public uint SleepUntil(uint fullTicks, uint subTicks) { m_sleepUntilFullTicks = fullTicks; m_sleepUntilSubTicks = subTicks; /** * If we're the only thread that and we are sleeping, we have nowhere to switch to * when we have a taskswitch that happens. * This case can only happen if we're the KernelTask with all threads sleeping but this one, so we just wait here */ if (OwningTask == Tasking.KernelTask && OwningTask.ThreadCount == OwningTask.SleepingThreadCount + 1) { while (!hasSleepTimeExpired()) { // Wait for all interrupts, not just a task switch... CPU.HLT(); } } else { AddFlag(ThreadFlags.SLEEPING); OwningTask.SleepingThreadCount++; // Will return when waiting is done Tasking.Yield(); } return(0); }
/// <summary> /// Processes a signal /// </summary> /// <param name="action">The action</param> /// <returns>The signal context</returns> public void ProcessSignal(SignalAction action) { while (m_currentSignalContext != null) { Tasking.Yield(); } m_signalMutex.Lock(); m_currentSignalContext = Context.ProcessSignal(action); m_signalMutex.Unlock(); }