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();
     }
 }
Пример #2
0
 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();
     }
 }
Пример #3
0
 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();
   }
 }