/// <summary> /// Add a trigger to the list of triggers pending insertion. /// It will not *finish* inserting it until the CPU tells us it's a good /// time to do so, by calling ActivatePendingTriggers(). /// It will also refuse to insert a WHEN/ON/LOCK trigger that's already either active /// or pending insertion to the active list (avoids duplication). /// </summary> /// <param name="trigger"></param> public void AddPendingTrigger(TriggerInfo trigger) { // CntainsTrigger is a sequential walk, but that should be okay // because it should be unlikely that there's hundreds of // triggers. There'll be at most tens of them, and even that's // unlikely. if (!ContainsTrigger(trigger)) { TriggersToInsert.Add(trigger); } }
/// <summary> /// Take all the pending triggers that have been added by AddPendingTrigger, /// and finally make them become active. To be called by the CPU when it /// decides that enough mainline code has had a chance to happen that it's /// okay to enable triggers again. /// </summary> public void ActivatePendingTriggers() { Triggers.AddRange(TriggersToInsert); TriggersToInsert.Clear(); }
/// <summary> /// True if the given trigger's IP is for a trigger that /// is currently active, or is about to become active. /// </summary> /// <param name="trigger"></param> /// <returns></returns> public bool ContainsTrigger(TriggerInfo trigger) { return(Triggers.Contains(trigger) || TriggersToInsert.Contains(trigger)); }
/// <summary> /// Remove a trigger from current triggers or pending insertion /// triggers or both if need be, so it's not there anymore at all. /// </summary> /// <param name="trigger"></param> public void RemoveTrigger(TriggerInfo trigger) { Triggers.Remove(trigger); // can ignore if it wasn't in the list. TriggersToInsert.Remove(trigger); // can ignore if it wasn't in the list. }
/// <summary> /// Remove all active and pending triggers. /// </summary> public void ClearTriggers() { Triggers.Clear(); TriggersToInsert.Clear(); }
/// <summary> /// Remove a trigger from current triggers or pending insertion /// triggers or both if need be, so it's not there anymore at all. /// </summary> /// <param name="trigger"></param> public void RemoveTrigger(TriggerInfo trigger) { Triggers.RemoveAll((item) => item.Equals(trigger)); // can ignore if it wasn't in the list. TriggersToInsert.RemoveAll((item) => item.Equals(trigger)); // can ignore if it wasn't in the list. }
/// <summary> /// True if the given trigger's IP is for a trigger that /// is currently active, or is about to become active. /// </summary> /// <param name="instructionPointer"></param> /// <returns></returns> public bool ContainsTrigger(int instructionPointer) { return(Triggers.Contains(instructionPointer) || TriggersToInsert.Contains(instructionPointer)); }
/// <summary> /// Remove a trigger from current triggers or pending insertion /// triggers or both if need be, so it's not there anymore at all. /// </summary> /// <param name="instructionPointer"></param> public void RemoveTrigger(int instructionPointer) { Triggers.Remove(instructionPointer); // can ignore if it wasn't in the list. TriggersToInsert.Remove(instructionPointer); // can ignore if it wasn't in the list. }
/// <summary> /// Take only those pending triggers that AddPendingTrigger added who's /// Priority is higher than the given value, and make them become active. /// ("active" here means "called on the callstack like a subroutine.") /// </summary> /// <param name="aboveThis"></param> public void ActivatePendingTriggersAbovePriority(InterruptPriority aboveThis) { Triggers.AddRange(TriggersToInsert.FindAll(t => t.Priority > aboveThis)); TriggersToInsert.RemoveAll(t => t.Priority > aboveThis); }