- Merge branch 0.3-r1003--scheduler-manage-preemption into trunk
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1023 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
cb5d958790
commit
df4b1b4205
11 changed files with 158 additions and 55 deletions
|
@ -58,3 +58,16 @@ the time slice will have to end before the former can run."""
|
|||
self.sort(queue,by_ltime)
|
||||
self.sort(queue,by_prio)
|
||||
|
||||
# manage preemption: see if we've a running thread
|
||||
# in the ready queue, and if it can still run
|
||||
if self.is_preemptive() == True:
|
||||
higher_prio = queue.get_item_at(0).get_current_priority()
|
||||
i = 0
|
||||
while i < queue.size():
|
||||
sched = queue.get_item_at(i)
|
||||
priority = sched.get_current_priority()
|
||||
if(priority != higher_prio):
|
||||
break
|
||||
if sched.get_state() == "running":
|
||||
queue.bubble_to_front(i)
|
||||
i += 1
|
||||
|
|
|
@ -53,3 +53,4 @@ Time Next in this case."""
|
|||
a.get_total_cpu_time() - a.get_elapsed_time() < \
|
||||
b.get_total_cpu_time() - b.get_elapsed_time()
|
||||
self.sort(queue,cmpf)
|
||||
|
||||
|
|
|
@ -150,15 +150,6 @@ namespace sgpem {
|
|||
public:
|
||||
virtual ~Schedulable() = 0;
|
||||
|
||||
enum state
|
||||
{
|
||||
state_running = 1<<0,
|
||||
state_ready = 1<<1,
|
||||
state_blocked = 1<<2,
|
||||
state_future = 1<<3,
|
||||
state_terminated = 1<<4
|
||||
};
|
||||
|
||||
virtual unsigned int get_arrival_time() const = 0;
|
||||
virtual unsigned int get_elapsed_time() const = 0;
|
||||
virtual int get_last_acquisition() const = 0;
|
||||
|
@ -166,7 +157,30 @@ namespace sgpem {
|
|||
virtual int get_base_priority() const = 0;
|
||||
virtual int get_current_priority() const = 0;
|
||||
virtual unsigned int get_total_cpu_time() const = 0;
|
||||
virtual state get_state() const = 0;
|
||||
|
||||
%ignore Schedulable::get_state() const;
|
||||
%extend {
|
||||
const char* get_state() const
|
||||
{
|
||||
switch(self->get_state())
|
||||
{
|
||||
case Schedulable::state_future:
|
||||
return "future";
|
||||
case Schedulable::state_terminated:
|
||||
return "terminated";
|
||||
case Schedulable::state_running:
|
||||
return "running";
|
||||
case Schedulable::state_ready:
|
||||
return "ready";
|
||||
case Schedulable::state_blocked:
|
||||
return "blocked";
|
||||
default:
|
||||
// should never get here
|
||||
return "undefined";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%ignore Schedulable::get_name() const;
|
||||
%extend {
|
||||
|
@ -204,6 +218,7 @@ namespace sgpem {
|
|||
sgpem::Thread& get_item_at(position index);
|
||||
|
||||
void swap(position a, position b) throw(std::out_of_range);
|
||||
void bubble_to_front(position x) throw(std::out_of_range);
|
||||
|
||||
private:
|
||||
// Avoid instantiation and copy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue