*** original_nodbg_scheduler.h	2011-05-29 19:32:45.110377873 -0300
--- scheduler.h	2011-05-29 20:13:36.338788526 -0300
***************
*** 14,170 ****
      class Priority
      {
      public:
! 	enum {
! 	    MAIN   = 0,
! 	    HIGH   = 1,
! 	    NORMAL = (unsigned(1) << (sizeof(int) * 8 - 1)) -3,
! 	    LOW    = (unsigned(1) << (sizeof(int) * 8 - 1)) -2,
! 	    IDLE   = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
! 	};
  
! 	static const bool timed = false;
! 	static const bool preemptive = true;
! 	static const bool energy_aware = false;
  
! 	static const unsigned int QUEUES = 1;
  
      public:
! 	Priority(int p = NORMAL): _priority(p) {}
  
! 	operator const volatile int() const volatile { return _priority; }
  
      protected:
! 	volatile int _priority;
      };
  
      // Round-Robin
      class Round_Robin: public Priority
      {
      public:
! 	enum {
! 	    MAIN   = 0,
! 	    NORMAL = 1,
! 	    IDLE   = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
! 	};
! 
! 	static const bool timed = true;
! 	static const bool preemptive = true;
! 	static const bool energy_aware = false;
  
      public:
! 	Round_Robin(int p = NORMAL): Priority(p) {}
      };
  
      // First-Come, First-Served (FIFO)
      class FCFS: public Priority
      {
      public:
! 	enum {
! 	    MAIN   = 0,
! 	    NORMAL = 1,
! 	    IDLE   = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
! 	};
! 
! 	static const bool timed = false;
! 	static const bool preemptive = false;
! 	static const bool energy_aware = false;
  
      public:
! 	FCFS(int p = NORMAL)
! 	    : Priority((p == IDLE) ? IDLE : TSC::time_stamp()) {}
      };
  
      // Rate Monotonic
      class RM: public Priority
      {
      public:
! 	enum {
! 	    MAIN      = 0,
! 	    PERIODIC  = 1,
! 	    APERIODIC = (unsigned(1) << (sizeof(int) * 8 - 1)) -2,
! 	    NORMAL    = APERIODIC,
! 	    IDLE      = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
! 	};
! 
! 	static const bool timed = true;
! 	static const bool preemptive = true;
! 	static const bool energy_aware = false;
  
      public:
! 	RM(int p): Priority(p), _deadline(0) {} // Aperiodic
! 	RM(const RTC::Microsecond & d): Priority(PERIODIC), _deadline(d) {}
  
      private:
! 	RTC::Microsecond _deadline;
      };
  
      // Energy-aware Rate Monotonic
      class EARM: public RM
      {
      public:
! 	enum {
! 	    MAIN	= 0,
! 	    PERIODIC	= 1,
! 	    APERIODIC	= (unsigned(1) << (sizeof(int) * 8 - 2)) - 1,
! 	    IDLE	= (unsigned(1) << (sizeof(int) * 8 - 2)),
! 	    BEST_EFFORT	= (unsigned(1) << (sizeof(int) * 8 - 2)) + 1,
! 	    NORMAL	= APERIODIC
! 	};
! 
! 	static const bool timed = true;
! 	static const bool preemptive = true;
! 	static const bool energy_aware = true;
  
      public:
! 	EARM(int p): RM(p) {}
! 	EARM(const RTC::Microsecond & d): RM(d) {}
      };
  
      // Earliest Deadline First
      class EDF: public Priority
      {
      public:
! 	enum {
! 	    MAIN      = 0,
! 	    PERIODIC  = 1,
! 	    APERIODIC = (unsigned(1) << (sizeof(int) * 8 - 1)) -2,
! 	    NORMAL    = APERIODIC,
! 	    IDLE      = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
! 	};
! 
! 	static const bool timed = false;
! 	static const bool preemptive = true;
! 	static const bool energy_aware = false;
  
      public:
! 	EDF(int p): Priority(p), _deadline(0) {} // Aperiodic
! 	EDF(const RTC::Microsecond & d): Priority(d >> 8), _deadline(d) {}
  
      private:
! 	RTC::Microsecond _deadline;
      };
  
      // CPU Affinity
      class CPU_Affinity: public Priority
      {
      public:
! 	static const unsigned int QUEUES = Traits<Machine>::MAX_CPUS;
    
      public:
! 	CPU_Affinity(int p = NORMAL): Priority(p),
! 	     _affinity(((p == IDLE) || (p == MAIN)) ? Machine::cpu_id()
! 		       : ++_next_cpu %= Machine::n_cpus()) {}
  
! 	CPU_Affinity(int p, int a): Priority(p), _affinity(a) {}
  
! 	const volatile int & queue() const volatile { return _affinity; }
  
! 	static int current() { return Machine::cpu_id(); }
  
      private:
! 	volatile int _affinity;
  
! 	static int _next_cpu;
      };
  };
  
--- 14,168 ----
      class Priority
      {
      public:
!         enum {
!             MAIN   = 0,
!             HIGH   = 1,
!             NORMAL = (unsigned(1) << (sizeof(int) * 8 - 1)) -3,
!             LOW    = (unsigned(1) << (sizeof(int) * 8 - 1)) -2,
!             IDLE   = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
!         };
  
!         static const bool timed = false;
!         static const bool preemptive = true;
!         static const bool energy_aware = false;
  
!         static const unsigned int QUEUES = 1;
  
      public:
!         Priority(int p = NORMAL): _priority(p) {}
  
!         operator const volatile int() const volatile { return _priority; }
  
      protected:
!         volatile int _priority;
      };
  
      // Round-Robin
      class Round_Robin: public Priority
      {
      public:
!         enum {
!             MAIN   = 0,
!             NORMAL = 1,
!             IDLE   = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
!         };
! 
!         static const bool timed = true;
!         static const bool preemptive = true;
!         static const bool energy_aware = false;
  
      public:
!         Round_Robin(int p = NORMAL): Priority(p) {}
      };
  
      // First-Come, First-Served (FIFO)
      class FCFS: public Priority
      {
      public:
!         enum {
!             MAIN   = 0,
!             NORMAL = 1,
!             IDLE   = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
!         };
! 
!         static const bool timed = false;
!         static const bool preemptive = false;
!         static const bool energy_aware = false;
  
      public:
!         FCFS(int p = NORMAL) : Priority((p == IDLE) ? IDLE : TSC::time_stamp()) {}
      };
  
      // Rate Monotonic
      class RM: public Priority
      {
      public:
!         enum {
!             MAIN      = 0,
!             PERIODIC  = 1,
!             APERIODIC = (unsigned(1) << (sizeof(int) * 8 - 1)) -2,
!             NORMAL    = APERIODIC,
!             IDLE      = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
!         };
! 
!         static const bool timed = true;
!         static const bool preemptive = true;
!         static const bool energy_aware = false;
  
      public:
!         RM(int p): Priority(p), _deadline(0) {} // Aperiodic
!         RM(const RTC::Microsecond & d): Priority(PERIODIC), _deadline(d) {}
  
      private:
!         RTC::Microsecond _deadline;
      };
  
      // Energy-aware Rate Monotonic
      class EARM: public RM
      {
      public:
!         enum {
!             MAIN    = 0,
!             PERIODIC    = 1,
!             APERIODIC   = (unsigned(1) << (sizeof(int) * 8 - 2)) - 1,
!             IDLE    = (unsigned(1) << (sizeof(int) * 8 - 2)),
!             BEST_EFFORT = (unsigned(1) << (sizeof(int) * 8 - 2)) + 1,
!             NORMAL  = APERIODIC
!         };
! 
!         static const bool timed = true;
!         static const bool preemptive = true;
!         static const bool energy_aware = true;
  
      public:
!         EARM(int p): RM(p) {}
!         EARM(const RTC::Microsecond & d): RM(d) {}
      };
  
      // Earliest Deadline First
      class EDF: public Priority
      {
      public:
!         enum {
!             MAIN      = 0,
!             PERIODIC  = 1,
!             APERIODIC = (unsigned(1) << (sizeof(int) * 8 - 1)) -2,
!             NORMAL    = APERIODIC,
!             IDLE      = (unsigned(1) << (sizeof(int) * 8 - 1)) -1
!         };
! 
!         static const bool timed = false;
!         static const bool preemptive = true;
!         static const bool energy_aware = false;
  
      public:
!         EDF(int p): Priority(p), _deadline(0) {} // Aperiodic
!         EDF(const RTC::Microsecond & d): Priority(d >> 8), _deadline(d) {}
  
      private:
!         RTC::Microsecond _deadline;
      };
  
      // CPU Affinity
      class CPU_Affinity: public Priority
      {
      public:
!         static const unsigned int QUEUES = Traits<Machine>::MAX_CPUS;
    
      public:
!         CPU_Affinity(int p = NORMAL): Priority(p),
!              _affinity(((p == IDLE) || (p == MAIN)) ? Machine::cpu_id() : ++_next_cpu %= Machine::n_cpus()) {}
  
!         CPU_Affinity(int p, int a): Priority(p), _affinity(a) {}
  
!         const volatile int & queue() const volatile { return _affinity; }
  
!         static int current() { return Machine::cpu_id(); }
  
      private:
!         volatile int _affinity;
  
!         static int _next_cpu;
      };
  };
  
***************
*** 185,220 ****
  
      unsigned int size() { return _ready[Criterion::current()].size(); }
  
!     Element * volatile & chosen() { 
! 	return _ready[Criterion::current()].chosen();
      }
  
      void insert(Element * e) {
! 	_ready[e->rank().queue()].insert(e); 
      }
  
!     Element * remove(Element * e) {
! 	// removing object instead of element forces a search and renders
! 	// removing inexistent objects harmless
! 	return _ready[e->rank().queue()].remove(e->object());
      }
  
!     Element * choose() {
! 	return _ready[Criterion::current()].choose();
      }
  
!     Element * choose_another() {
! 	return _ready[Criterion::current()].choose_another();
      }
  
!     Element * choose(Element * e) {
! 	return _ready[e->rank().queue()].choose(e->object());
      }
  
  private:
      Queue _ready[Q];
  };
  
  // Specialization for single-queue
  template <typename T>
  class Scheduling_Queue<T, 1>: public Scheduling_List<T, typename T::Criterion>
--- 183,219 ----
  
      unsigned int size() { return _ready[Criterion::current()].size(); }
  
!     Maybe<Element*> volatile & chosen() { 
!         return _ready[Criterion::current()].chosen();
      }
  
      void insert(Element * e) {
!         _ready[e->rank().queue()].insert(e); 
      }
  
!     Maybe<Element*> remove(Element * e) {
!         // removing object instead of element forces a search and renders
!         // removing inexistent objects harmless
!         return _ready[e->rank().queue()].remove(e->object());
      }
  
!     Maybe<Element*> choose() {
!         return _ready[Criterion::current()].choose();
      }
  
!     Maybe<Element*> choose_another() {
!         return _ready[Criterion::current()].choose_another();
      }
  
!     Maybe<Element*> choose(Element * e) {
!         return _ready[e->rank().queue()].choose(e->object());
      }
  
  private:
      Queue _ready[Q];
  };
  
+ 
  // Specialization for single-queue
  template <typename T>
  class Scheduling_Queue<T, 1>: public Scheduling_List<T, typename T::Criterion>
***************
*** 226,243 ****
      typedef typename Base::Element Element;
  
  public:
!     Element * remove(Element * e) {
! 	// removing object instead of element forces a search and renders
! 	// removing inexistent objects harmless
! 	return Base::remove(e->object());
      }
  
!     Element * choose() {
! 	return Base::choose();
      }
  
!     Element * choose(Element * e) {
! 	return Base::choose(e->object());
      }
  };
  
--- 225,242 ----
      typedef typename Base::Element Element;
  
  public:
!     Maybe<Element*> remove(Element * e) {
!         // removing object instead of element forces a search and renders
!         // removing inexistent objects harmless
!         return Base::remove(e->object());
      }
  
!     Maybe<Element*> choose() {
!         return Base::choose();
      }
  
!     Maybe<Element*> choose(Element * e) {
!         return Base::choose(e->object());
      }
  };
  
***************
*** 263,302 ****
  
      unsigned int schedulables() { return Base::size(); }
  
!     T * volatile chosen() { 
! 	return const_cast<T * volatile>(Base::chosen()->object()); 
      }
  
!     void insert(T * obj) {
! 	Base::insert(obj->link()); 
      }
  
!     T * remove(T * obj) {
! 	return Base::remove(obj->link()) ? obj : 0;
      }
  
!     void suspend(T * obj) {
! 	Base::remove(obj->link());
      }
  
!     void resume(T * obj) {
! 	Base::insert(obj->link());
      }
  
!     T * choose() {
! 	T * obj = Base::choose()->object();
! 	return obj;
      }
  
!     T * choose_another() {
! 	T * obj = Base::choose_another()->object();
! 	return obj;
      }
  
!     T * choose(T * obj) {
! 	if(!Base::choose(obj->link()))
! 	    obj = 0;
! 	return obj;
      }
  };
  
--- 262,299 ----
  
      unsigned int schedulables() { return Base::size(); }
  
!     Maybe<T> volatile chosen() { 
!         return Base::chosen()->object();
      }
  
!     void insert(T obj) {
!         Base::insert(obj.link()); 
      }
  
!     Maybe<T> remove(T obj) {
!         return Base::remove(obj.link()) ? Maybe<T>(obj) : Maybe<T>();
      }
  
!     void suspend(T obj) {
!         Base::remove(obj.link());
      }
  
!     void resume(T obj) {
!         Base::insert(obj.link());
      }
  
!     Maybe<T> choose() {
!         Maybe<Element*> e = Base::choose();
!         return e.exists() ? Maybe<T>(e.get()->object()) : Maybe<T>();
      }
  
!     Maybe<T> choose_another() {
!         Maybe<Element*> e = Base::choose_another();
!         return e.exists() ? Maybe<T>(e.get()->object()) : Maybe<T>();
      }
  
!     Maybe<T> choose(T obj) {
!         return Maybe<T>(obj, Base::choose(obj.link()));
      }
  };
  
