]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/l4_buf_iter.cpp
update
[l4.git] / kernel / fiasco / src / kern / l4_buf_iter.cpp
1 INTERFACE:
2
3 #include <types.h>
4 #include <l4_msg_item.h>
5 #include <l4_fpage.h>
6 #include <l4_types.h>
7
8 class L4_buf_iter
9 {
10 public:
11   struct Item
12   {
13     L4_msg_item b;
14     Mword d;
15
16     Item() : b(0)
17 #ifndef NDEBUG
18              , d(0)
19 #endif
20     {}
21   };
22
23   explicit L4_buf_iter(Utcb const *utcb, unsigned start)
24   : _buf(&utcb->buffers[start]), _max(&utcb->buffers[Utcb::Max_buffers])
25   { next(); }
26   bool more() const { return _buf < _max; }
27   Item const *get() const { return &c; }
28   bool next();
29
30 private:
31   Mword const *_buf;
32   Mword const *const _max;
33   Item c;
34 };
35
36 class L4_snd_item_iter
37 {
38 public:
39   struct Item
40   {
41     L4_msg_item b;
42     Mword d;
43
44     Item()
45     : b(0)
46 #ifndef NDEBUG
47       , d(0)
48 #endif
49     {}
50   };
51
52   explicit L4_snd_item_iter(Utcb const *utcb, unsigned offset)
53   : _buf(&utcb->values[offset]),
54     _max(&utcb->values[Utcb::Max_words]) {}
55   bool more() const { return _buf < _max; }
56   Item const *get() const { return &c; }
57   bool next();
58
59 private:
60   Mword const *_buf;
61   Mword const *const _max;
62   Item c;
63 };
64
65 //----------------------------------------------------------------------------
66 IMPLEMENTATION:
67
68 IMPLEMENT inline
69 bool
70 L4_buf_iter::next()
71 {
72   c.b = L4_msg_item(_buf[0]);
73   if (EXPECT_FALSE(c.b.is_void()))
74     return false;
75
76   if (c.b.type() == L4_msg_item::Map && c.b.is_small_obj())
77     c.d = c.b.get_small_buf().raw();
78   else
79     {
80       ++_buf;
81       if (EXPECT_FALSE(_buf >= _max))
82         {
83           c.b = L4_msg_item(0);
84           return false;
85         }
86
87       c.d = _buf[0];
88     }
89   ++_buf;
90   return true;
91 }
92
93
94 IMPLEMENT inline
95 bool
96 L4_snd_item_iter::next()
97 {
98   c.b = L4_msg_item(_buf[0]);
99
100   ++_buf;
101
102   if (EXPECT_FALSE(c.b.is_void()))
103     return true;
104
105   if (EXPECT_FALSE(_buf >= _max))
106     return false;
107
108   c.d = _buf[0];
109
110   ++_buf;
111   return true;
112 }