]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/sched_context.cpp
update
[l4.git] / kernel / fiasco / src / kern / sched_context.cpp
1 INTERFACE:
2 #include "per_cpu_data.h"
3
4 EXTENSION class Sched_context
5 {
6 private:
7   static Per_cpu<Ready_queue> _ready_q;
8 };
9
10 IMPLEMENTATION:
11
12 #include "kdb_ke.h"
13
14 DEFINE_PER_CPU Per_cpu<Sched_context::Ready_queue> Sched_context::_ready_q;
15
16 PUBLIC static inline
17 Sched_context::Ready_queue &
18 Sched_context::rq(unsigned cpu)
19 { return _ready_q.cpu(cpu); }
20
21
22 /**
23  * \param cpu must be current_cpu()
24  */
25 PUBLIC inline NEEDS["kdb_ke.h"]
26 void
27 Sched_context::deblock(unsigned cpu)
28 {
29   assert_kdb(cpu_lock.test());
30
31   Sched_context *cs = rq(cpu).current_sched();
32   if (this != cs)
33       deblock_refill(cpu);
34
35   ready_enqueue(cpu);
36 }
37
38 /**
39  * \param cpu must be current_cpu()
40  * \param crs the Sched_context of the current context
41  * \param lazy_q queue lazily if applicable
42  */
43 PUBLIC inline NEEDS["kdb_ke.h"]
44 bool
45 Sched_context::deblock(unsigned cpu, Sched_context *crs, bool lazy_q = false)
46 {
47   assert_kdb(cpu_lock.test());
48
49   Sched_context *cs = rq(cpu).current_sched();
50   bool res = true;
51   if (this == cs)
52     {
53       if (crs->dominates(this))
54         res = false;
55     }
56   else
57     {
58       deblock_refill(cpu);
59
60       if ((EXPECT_TRUE(cs != 0) && cs->dominates(this)) || crs->dominates(this))
61         res = false;
62     }
63
64   if (res && lazy_q)
65     return true;
66
67   ready_enqueue(cpu);
68   return res;
69 }
70