コード例 #1
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();
     }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        public virtual Release Release(PreemptiveRequest request)
        {
            var release = new Release(Environment, request, TriggerRequest);

            ReleaseQueue.Enqueue(release);
            TriggerRelease();
            return(release);
        }
コード例 #5
0
        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);
        }
コード例 #6
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();
     }
 }
コード例 #7
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();
   }
 }
コード例 #8
0
 public virtual Release Release(PreemptiveRequest request) {
   var release = new Release(Environment, request, TriggerRequest);
   ReleaseQueue.Enqueue(release);
   TriggerRelease();
   return release;
 }