Skip to content

Commit 9d48f0e

Browse files
committed
lib::intrusive_list
1 parent 85289c4 commit 9d48f0e

File tree

12 files changed

+351
-105
lines changed

12 files changed

+351
-105
lines changed

kernel/interfaces/deps/frigg.cppm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ export namespace frg
1717
{
1818
using ::frg::pairing_heap;
1919
using ::frg::pairing_heap_hook;
20-
using ::frg::rbtree;
21-
using ::frg::rbtree_hook;
22-
using ::frg::intrusive_list;
2320
using ::frg::locate_member;
2421
using ::frg::small_vector;
2522
using ::frg::manual_box;
2623
using ::frg::slab_pool;
2724
using ::frg::slab_allocator;
2825

29-
using ::frg::default_list_hook;
30-
3126
template<typename Type>
3227
struct allocator : std::allocator<Type>
3328
{

kernel/interfaces/drivers/fs/dev/tty.cppm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export module drivers.fs.dev.tty;
44

55
import system.vfs;
66
import lib;
7-
import frigg;
87
import std;
98

109
export namespace fs::dev::tty
@@ -251,8 +250,6 @@ export namespace fs::dev::tty
251250

252251
std::weak_ptr<instance> link;
253252

254-
frg::default_list_hook<instance> hook;
255-
256253
instance(driver *drv, std::uint32_t minor, std::unique_ptr<line_discipline> ldisc);
257254

258255
virtual ~instance() = default;
@@ -305,7 +302,7 @@ export namespace fs::dev::tty
305302
>, lib::mutex
306303
> instances;
307304

308-
frg::default_list_hook<driver> hook;
305+
lib::intrusive_list_hook<driver> hook;
309306

310307
driver(std::string_view name, std::uint32_t major, std::uint32_t minor_start, const ktermios &init_termios)
311308
: name { name }, major { major }, minor_start { minor_start }, init_termios { init_termios } { }

kernel/interfaces/lib/initgraph.cppm

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
export module lib:initgraph;
44

55
import :log;
6+
import :list;
67
import :bug_on;
78
import :panic;
8-
import frigg;
99
import std;
1010

1111
// this code is yoinked from managarm
@@ -34,8 +34,8 @@ export namespace lib::initgraph
3434
node *_source;
3535
node *_target;
3636

37-
frg::default_list_hook<edge> _outhook;
38-
frg::default_list_hook<edge> _inhook;
37+
lib::intrusive_list_hook<edge> _outhook;
38+
lib::intrusive_list_hook<edge> _inhook;
3939

4040
public:
4141
edge(node *source, node *target)
@@ -59,26 +59,11 @@ export namespace lib::initgraph
5959
engine *_engine;
6060
std::string_view _name;
6161

62-
frg::intrusive_list<
63-
edge,
64-
frg::locate_member<
65-
edge,
66-
frg::default_list_hook<edge>,
67-
&edge::_outhook
68-
>
69-
> _outlist;
70-
71-
frg::intrusive_list<
72-
edge,
73-
frg::locate_member<
74-
edge,
75-
frg::default_list_hook<edge>,
76-
&edge::_inhook
77-
>
78-
> _inlist;
79-
80-
frg::default_list_hook<node> _nodeshook;
81-
frg::default_list_hook<node> _queuehook;
62+
lib::intrusive_list<edge, &edge::_outhook> _outlist;
63+
lib::intrusive_list<edge, &edge::_inhook> _inlist;
64+
65+
lib::intrusive_list_hook<node> _nodeshook;
66+
lib::intrusive_list_hook<node> _queuehook;
8267

8368
bool _wanted = false;
8469
bool _done = false;
@@ -108,23 +93,8 @@ export namespace lib::initgraph
10893
friend void realise_node(node *node);
10994

11095
private:
111-
frg::intrusive_list<
112-
node,
113-
frg::locate_member<
114-
node,
115-
frg::default_list_hook<node>,
116-
&node::_nodeshook
117-
>
118-
> _nodes;
119-
120-
frg::intrusive_list<
121-
node,
122-
frg::locate_member<
123-
node,
124-
frg::default_list_hook<node>,
125-
&node::_queuehook
126-
>
127-
> _pending;
96+
lib::intrusive_list<node, &node::_nodeshook> _nodes;
97+
lib::intrusive_list<node, &node::_queuehook> _pending;
12898

12999
std::string_view _name;
130100

@@ -173,16 +143,16 @@ export namespace lib::initgraph
173143
if constexpr (debug)
174144
lib::debug("initgraph: running engine '{}'", _name);
175145

176-
for (auto node : _nodes)
177-
node->_wanted = true;
146+
for (auto &node : _nodes)
147+
node._wanted = true;
178148

179-
for (auto node : _nodes)
149+
for (auto &node : _nodes)
180150
{
181-
if (!node->_wanted || node->_done)
151+
if (!node._wanted || node._done)
182152
continue;
183153

184-
if (node->unsatisfied == 0)
185-
_pending.push_back(node);
154+
if (node.unsatisfied == 0)
155+
_pending.push_back(std::addressof(node));
186156
}
187157

188158
while (!_pending.empty())
@@ -199,9 +169,9 @@ export namespace lib::initgraph
199169
if constexpr (debug)
200170
post_activate(current);
201171

202-
for (auto edge : current->_outlist)
172+
for (auto &edge : current->_outlist)
203173
{
204-
auto successor = edge->_target;
174+
auto successor = edge._target;
205175
lib::bug_on(successor->unsatisfied == 0);
206176
successor->unsatisfied--;
207177

@@ -211,12 +181,12 @@ export namespace lib::initgraph
211181
}
212182

213183
std::uint32_t unreached = 0;
214-
for (auto node : _nodes)
184+
for (auto &node : _nodes)
215185
{
216-
if (!node->_wanted || node->_done)
186+
if (!node._wanted || node._done)
217187
continue;
218188

219-
report_unreached(node);
189+
report_unreached(std::addressof(node));
220190
unreached++;
221191
}
222192

@@ -245,7 +215,8 @@ export namespace lib::initgraph
245215
edge->_target->_inlist.push_back(edge);
246216
edge->_target->unsatisfied++;
247217

248-
// edge->source()->engine()->on_realise_edge(edge);
218+
// if constexpr (debug)
219+
// edge->source()->engine()->on_realise_edge(edge);
249220
}
250221

251222
struct stage final : public node

kernel/interfaces/lib/lib.cppm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export import :errno;
1212
export import :hash;
1313
export import :initgraph;
1414
export import :io;
15+
export import :list;
1516
export import :locker;
1617
export import :log;
1718
export import :map;

0 commit comments

Comments
 (0)