/// <summary> /// Called when this event is "yielded" by some process. /// </summary> internal void Subscribe(SimProcess subscriber) { if (InFinalState || !CanHaveSubscribers) { return; } if (Subscribers == null) { Subscribers = subscriber; } else if (Subscribers.Count == 1) { if (!Subscribers.First.Equals(subscriber)) { var sub = new SinglyLinkedList <SimProcess>(); sub.AddLast(Subscribers as SimProcess); sub.AddLast(subscriber); Subscribers = sub; } } else if (!Subscribers.Contains(subscriber)) { Subscribers.AddLast(subscriber); } Debug.Assert(ReferenceEquals(Env.ActiveProcess, subscriber)); Env.UnscheduleActiveProcess(); }
public static void Resume(this SimProcess process, double delay) { SimEvent <object> suspend; if (SuspendInfo[process.Env].TryGetValue(process, out suspend)) { process.Env.Process(ResumeDelayed(suspend, delay)); } }
public static void Resume(this SimProcess process) { SimEvent <object> suspend; if (SuspendInfo[process.Env].TryGetValue(process, out suspend)) { suspend.TrySucceed(); } }
internal SimProcess ScheduleProcess(SimProcess process) { if (!process.Succeeded && !process.Scheduled) { process.At = Now; process.Version = _lowPriority++; _processes.Add(process); } return(process); }
internal void RemoveSubscriber(SimProcess subscriber) { if (InFinalState || !CanHaveSubscribers) { return; } Debug.Assert(!ReferenceEquals(Subscribers, null)); Debug.Assert(Subscribers.Contains(subscriber)); Debug.Assert(!ReferenceEquals(Env.ActiveProcess, subscriber)); if (Subscribers.Count == 1) { Subscribers = null; } else { Subscribers.Remove(subscriber); } }
/// <summary> /// </summary> /// <param name="seed"></param> internal SimEnvironment(int seed) { // We add a dummy timeout event and a dummy process, so that heaps are never empty. They // have the maximum priority available, since they never have to be called. const double maxPr = double.PositiveInfinity; const ulong maxVer = ulong.MaxValue; var dummyP = new SimProcess(this, DummyProcess()) { At = maxPr, Version = maxVer }; var dummyEv = new Dummy(this) { At = maxPr, Version = maxVer }; _processes = new OptimizedSkewHeap(dummyP); _events = new OptimizedSkewHeap(dummyEv); Random = TRandom.New(new MT19937Generator(seed)); EndEvent = new Dummy(this); }
internal PreemptionInfo(SimProcess by, Double usageSince) { _by = by; _usageSince = usageSince; }