]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/src/kern/sched_context-fp_wfq.cpp
update
[l4.git] / kernel / fiasco / src / kern / sched_context-fp_wfq.cpp
index 66cc4e6981b794689b88b85e333a04633636cf23..6610945df3ea17d08368a66365dfe64203f3ab6f 100644 (file)
@@ -3,49 +3,29 @@ INTERFACE [sched_fp_wfq]:
 #include "ready_queue_fp.h"
 #include "ready_queue_wfq.h"
 
-
 class Sched_context
 {
   MEMBER_OFFSET();
   friend class Jdb_list_timeouts;
   friend class Jdb_thread_list;
 
-public:
-  enum Type { Fixed_prio, Wfq };
-
-  struct Ready_queue
+  struct Ready_list_item_concept
   {
-  public:
-    Ready_queue_fp<Sched_context> fp_rq;
-    Ready_queue_wfq<Sched_context> wfq_rq;
-    Context *schedule_in_progress;
-    Sched_context *current_sched() const { return _current_sched; }
-    void activate(Sched_context *s)
-    {
-      if (s && s->_t == Wfq)
-       wfq_rq.activate(s);
-      _current_sched = s;
-    }
-
-  private:
-    Sched_context *_current_sched;
-
-    friend class Jdb_thread_list;
-
-  public:
-    void set_idle(Sched_context *sc)
-    { sc->_t = Wfq; sc->_sc.wfq._p = 0; wfq_rq.set_idle(sc); }
-
-    void enqueue(Sched_context *);
-    void dequeue(Sched_context *);
-    Sched_context *next_to_run() const;
+    typedef Sched_context Item;
+    static Sched_context *&next(Sched_context *e) { return e->_sc.fp._ready_next; }
+    static Sched_context *&prev(Sched_context *e) { return e->_sc.fp._ready_prev; }
+    static Sched_context const *next(Sched_context const *e)
+    { return e->_sc.fp._ready_next; }
+    static Sched_context const *prev(Sched_context const *e)
+    { return e->_sc.fp._ready_prev; }
   };
 
-  Context *context() const { return context_of(this); }
+public:
+  enum Type { Fixed_prio, Wfq };
 
-private:
+  typedef cxx::Sd_list<Sched_context, Ready_list_item_concept> Fp_list;
 
-  unsigned short _p;
+private:
   Type _t;
 
   struct B_sc
@@ -60,8 +40,7 @@ private:
 
   struct Fp_sc : public B_sc
   {
-    Sched_context *_ready_next;
-    Sched_context *_ready_prev;
+    Sched_context *_ready_next, *_ready_prev;
   };
 
   struct Wfq_sc : public B_sc
@@ -87,11 +66,38 @@ private:
 
   Sc _sc;
 
-
 public:
   static Wfq_sc *wfq_elem(Sched_context *x) { return &x->_sc.wfq; }
-  static Fp_sc *fp_elem(Sched_context *x) { return &x->_sc.fp; }
 
+  struct Ready_queue
+  {
+  public:
+    Ready_queue_fp<Sched_context> fp_rq;
+    Ready_queue_wfq<Sched_context> wfq_rq;
+    Context *schedule_in_progress;
+    Sched_context *current_sched() const { return _current_sched; }
+    void activate(Sched_context *s)
+    {
+      if (s && s->_t == Wfq)
+       wfq_rq.activate(s);
+      _current_sched = s;
+    }
+
+  private:
+    Sched_context *_current_sched;
+
+    friend class Jdb_thread_list;
+
+  public:
+    void set_idle(Sched_context *sc)
+    { sc->_t = Wfq; sc->_sc.wfq._p = 0; wfq_rq.set_idle(sc); }
+
+    void enqueue(Sched_context *);
+    void dequeue(Sched_context *);
+    Sched_context *next_to_run() const;
+  };
+
+  Context *context() const { return context_of(this); }
 };
 
 
@@ -110,9 +116,9 @@ PUBLIC
 Sched_context::Sched_context()
 {
   _t = Fixed_prio;
-  _sc.fp._p = Config::default_prio;
-  _sc.fp._q = Config::default_time_slice;
-  _sc.fp._left = Config::default_time_slice;
+  _sc.fp._p = Config::Default_prio;
+  _sc.fp._q = Config::Default_time_slice;
+  _sc.fp._left = Config::Default_time_slice;
   _sc.fp._ready_next = 0;
 }
 
@@ -135,6 +141,9 @@ PUBLIC inline
 Mword
 Sched_context::in_ready_list() const
 {
+  // this magically works for the fp list and the heap,
+  // because wfq._ready_link and fp._ready_next are the
+  // same memory location
   return _sc.wfq._ready_link != 0;
 }