]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/context_base.cpp
5ea22f666af2393a4a0a0e0bded4910a2f9220b8
[l4.git] / kernel / fiasco / src / kern / context_base.cpp
1 INTERFACE:
2
3 #include "types.h"
4 #include "config_tcbsize.h"
5
6 class Context;
7
8 class Context_base
9 {
10 public:
11   enum
12   {
13     Size = THREAD_BLOCK_SIZE
14   };
15
16   // This virtual dtor enforces that Context / Thread / Context_base
17   // all start at offset 0
18   virtual ~Context_base() = 0;
19
20 protected:
21   friend unsigned &__cpu_of(const void *);
22   Mword _state;
23   unsigned _cpu;
24 };
25
26
27 //---------------------------------------------------------------------------
28 IMPLEMENTATION:
29
30 #include "config.h"
31 #include "processor.h"
32
33 IMPLEMENT inline Context_base::~Context_base() {}
34
35 inline NEEDS ["config.h"]
36 Context *context_of(const void *ptr)
37 {
38   return reinterpret_cast<Context *>
39     (reinterpret_cast<unsigned long>(ptr) & ~(Context_base::Size - 1));
40 }
41
42 inline NEEDS [context_of, "processor.h"]
43 Context *current()
44 { return context_of((void *)Proc::stack_pointer()); }
45
46 inline NEEDS ["config.h"]
47 unsigned &__cpu_of(const void *ptr)
48 { return reinterpret_cast<Context_base*>(context_of(ptr))->_cpu; }
49
50 inline NEEDS [__cpu_of]
51 void set_cpu_of(const void *ptr, unsigned cpu)
52 { __cpu_of(ptr) = cpu; }
53
54
55 inline NEEDS [__cpu_of]
56 unsigned cpu_of(const void *ptr)
57 { return __cpu_of(ptr); }
58
59 //---------------------------------------------------------------------------
60 IMPLEMENTATION [!mp]:
61
62 inline
63 unsigned current_cpu()
64 { return 0; }
65
66 //---------------------------------------------------------------------------
67 IMPLEMENTATION [mp]:
68
69 inline NEEDS [current, cpu_of]
70 unsigned current_cpu()
71 { return cpu_of(current()); }
72