示例#1
0
 def is_valid_proc_pid(self, pid):
     try:
         Process.cache(pid)
     except KeyError:
         raise ex.exceptions.InvalidProcId(\
             "Process with pid " + str(pid) + " not added to " +\
             "scheduler"
         )
     return True
示例#2
0
 def proc_priority(self, entity, new_priority = None):
     try:
         pid = entity.pid
     except AttributeError:
         pid = entity
     if self.is_valid_proc_pid(pid):
         if new_priority is None:
             return Process.cache(pid).priority
         # decide the priority op - inc or dec?
         proc = Process.cache(pid)
         old_priority = proc.priority
         op = 'dec'
         if new_priority > old_priority:
             op = 'inc'
         proc.priority = new_priority
         self.runq.update_key(pid, new_priority, op)
         if self.debug:
             self.dump_runq()
     return True
示例#3
0
 def dump_runq(self):
     q_iter = self.runq.get_iter()
     proc_list = []
     while (1):
         try:
             pid = q_iter.next()
             proc = Process.cache(pid)
             proc_list.append(str(proc))
         except StopIteration:
             break
     if len(proc_list) > 0:
         proc_list.append("\n")
     return ' '.join(proc_list)
示例#4
0
 def extract_qualifier_proc(self):
     max_proc = Process.cache(self.runq.extract_max())
     if self.debug:
         print self
     return max_proc
示例#5
0
 def read_qualifier_proc(self):
     if self.debug:
         print self
     return Process.cache(self.runq.maximum())
示例#6
0
 def cmp_proc_priority(self, id1, id2):
     if self.is_valid_proc_pid(id1) and \
        self.is_valid_proc_pid(id2):
         return Process.cache(id1).priority - \
                Process.cache(id2).priority