protected virtual void DoRequest(PreemptiveRequest request) { if (Users.Count >= Capacity && request.Preempt) { // Check if we can preempt another process var oldest = Users.OfType <PreemptiveRequest>().Select((r, i) => new { Request = r, Index = i }) .OrderByDescending(x => x.Request.Priority) .ThenByDescending(x => x.Request.Time) .ThenByDescending(x => x.Request.Preempt) .ThenByDescending(x => x.Index) .First().Request; if (oldest.Priority > request.Priority || (oldest.Priority == request.Priority && (!oldest.Preempt && request.Preempt || (oldest.Preempt == request.Preempt && oldest.Time > request.Time)))) { Users.Remove(oldest); oldest.Process.Interrupt(new Preempted(request.Process, oldest.Time)); } } if (Users.Count < Capacity) { Users.Add(request); request.Succeed(); } }
public virtual PreemptiveRequest Request(int priority = 1, bool preempt = false) { var request = new PreemptiveRequest(Environment, TriggerRelease, DisposeCallback, priority, preempt); if (!RequestQueue.ContainsKey(request.Priority)) RequestQueue.Add(request.Priority, new LinkedList<PreemptiveRequest>()); RequestQueue[request.Priority].AddLast(request); TriggerRequest(); return request; }
public virtual PreemptiveRequest Request(double priority = 1, bool preempt = false) { var request = new PreemptiveRequest(Environment, TriggerRelease, DisposeCallback, priority, preempt); RequestQueue.Enqueue(request); TriggerRequest(); return(request); }
public virtual Release Release(PreemptiveRequest request) { var release = new Release(Environment, request, TriggerRequest); ReleaseQueue.Enqueue(release); TriggerRelease(); return(release); }
public virtual PreemptiveRequest Request(int priority = 1, bool preempt = false) { var request = new PreemptiveRequest(Environment, TriggerRelease, DisposeCallback, priority, preempt); if (!RequestQueue.ContainsKey(request.Priority)) { RequestQueue.Add(request.Priority, new LinkedList <PreemptiveRequest>()); } RequestQueue[request.Priority].AddLast(request); TriggerRequest(); return(request); }
protected virtual void DoRequest(PreemptiveRequest request) { if (Users.Count >= Capacity && request.Preempt) { // Check if we can preempt another process // MaxItems are the least important according to priorty, time, and preemption flag var preempt = Users.MaxItems(x => x).Last(); if (preempt.CompareTo(request) > 0) { preempt.IsPreempted = true; Users.Remove(preempt); preempt.Owner?.Interrupt(new Preempted(request.Owner, preempt.Time)); } } if (Users.Count < Capacity) { Users.Add(request); request.Succeed(); } }
protected virtual void DoRequest(PreemptiveRequest request) { if (Users.Count >= Capacity && request.Preempt) { // Check if we can preempt another process var oldest = Users.OfType<PreemptiveRequest>().Select((r, i) => new { Request = r, Index = i }) .OrderByDescending(x => x.Request.Priority) .ThenByDescending(x => x.Request.Time) .ThenByDescending(x => x.Request.Preempt) .ThenByDescending(x => x.Index) .First().Request; if (oldest.Priority > request.Priority || (oldest.Priority == request.Priority && (!oldest.Preempt && request.Preempt || (oldest.Preempt == request.Preempt && oldest.Time > request.Time)))) { Users.Remove(oldest); oldest.Process.Interrupt(new Preempted(request.Process, oldest.Time)); } } if (Users.Count < Capacity) { Users.Add(request); request.Succeed(); } }
public virtual Release Release(PreemptiveRequest request) { var release = new Release(Environment, request, TriggerRequest); ReleaseQueue.Enqueue(release); TriggerRelease(); return release; }