Skip to content

Commit e692910

Browse files
committed
wip
1 parent 887fe71 commit e692910

File tree

41 files changed

+1104
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1104
-133
lines changed

meta/image/boot/loader.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"name": "Mobile",
88
"kernel": "bundle://hjert/_bin",
99
"blobs": [
10-
"bundle://system-srv/_bin",
11-
"bundle://device-srv/_bin",
10+
"bundle://grund-system/_bin",
11+
"bundle://grund-device/_bin",
1212
{
1313
"url": "bundle://hideo-shell/_bin",
1414
"props": {
@@ -26,8 +26,8 @@
2626
"name": "Desktop",
2727
"kernel": "bundle://hjert/_bin",
2828
"blobs": [
29-
"bundle://system-srv/_bin",
30-
"bundle://device-srv/_bin",
29+
"bundle://grund-system/_bin",
30+
"bundle://grund-device/_bin",
3131
{
3232
"url": "bundle://hideo-shell/_bin",
3333
"props": {
@@ -41,8 +41,8 @@
4141
"name": "Headless",
4242
"kernel": "bundle://hjert/_bin",
4343
"blobs": [
44-
"bundle://system-srv/_bin",
45-
"bundle://device-srv/_bin"
44+
"bundle://grund-system/_bin",
45+
"bundle://grund-device/_bin"
4646
]
4747
}
4848
]

meta/plugins/start-cmd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def bootCmd(args: Args) -> None:
187187
image.installTo("loader", efiTarget, "EFI/BOOT/BOOTX64.EFI")
188188
image.install("hjert", kernelTarget)
189189
image.install("limine-tests", kernelTarget)
190-
image.install("system-srv", skiftTarget)
191-
image.install("device-srv", skiftTarget)
190+
image.install("grund-system", skiftTarget)
191+
image.install("grund-device", skiftTarget)
192192
image.install("hideo-shell", skiftTarget)
193193
image.install("skift-branding", skiftTarget)
194194
image.install("skift-wallpapers", skiftTarget)

src/impls/impl-posix/async.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <karm-async/async.h>
2+
#include <karm-sys/proc.h>
3+
4+
namespace Karm::Async::_Embed {
5+
6+
struct PosixLoop : public Loop {
7+
TimeStamp _now;
8+
9+
PosixLoop(TimeStamp now) : _now(now) {}
10+
11+
TimeStamp now() override {
12+
return _now;
13+
}
14+
15+
Res<> wait(TimeStamp until) override {
16+
try$(Sys::sleepUntil(until));
17+
_now = Sys::now();
18+
return Ok();
19+
}
20+
};
21+
22+
static Opt<PosixLoop> _loop;
23+
Loop &loop() {
24+
if (not _loop) {
25+
_loop.emplace(Sys::now());
26+
}
27+
return *_loop;
28+
}
29+
30+
} // namespace Karm::Async::_Embed

src/impls/impl-skift/async.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <karm-async/_embed.h>
2+
3+
namespace Karm::Async::_Embed {
4+
5+
} // namespace Karm::Async::_Embed

src/kernel/hjert-core/entry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Res<> validateAndDump(u64 magic, Handover::Payload &payload) {
4949
}
5050

5151
Res<> enterUserspace(Handover::Payload &payload) {
52-
auto const *record = payload.fileByName("bundle://system-srv/_bin");
52+
auto const *record = payload.fileByName("bundle://grund-system/_bin");
5353
if (not record) {
5454
logInfo("entry: handover: no init file");
5555
return Error::invalidInput("No init file");

src/libs/karm-async/_embed.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
namespace Karm::Async {
4+
struct Loop;
5+
namespace _Embed {
6+
Loop &loop();
7+
} // namespace _Embed
8+
} // namespace Karm::Async

src/libs/karm-async/async.cpp

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#include <karm-logger/logger.h>
2+
3+
#include "async.h"
4+
5+
namespace Karm::Async {
6+
7+
/* --- Sink --- */
8+
9+
void Loop::_post(Sink &sink, Box<Event> event) {
10+
_queued.emplaceBack(sink, std::move(event));
11+
}
12+
13+
void Loop::_move(Sink &from, Sink &to) {
14+
logInfo("Moving sink from {p} to {p}", &from, &to);
15+
for (auto &q : _queued) {
16+
if (q.sink == &from) {
17+
q.sink = &to;
18+
}
19+
}
20+
21+
for (auto &s : _sources) {
22+
if (s.sink == &from) {
23+
s.sink = &to;
24+
}
25+
}
26+
}
27+
28+
void Loop::_dtor(Sink &sink) {
29+
for (auto &q : _queued) {
30+
if (q.sink == &sink)
31+
q.sink = nullptr;
32+
}
33+
34+
for (auto &s : _sources) {
35+
if (s.sink == &sink)
36+
s.sink = nullptr;
37+
}
38+
}
39+
40+
/* --- Source --- */
41+
42+
void Loop::_bind(Source &source, Sink &sink) {
43+
_sources.emplaceBack(source, sink);
44+
}
45+
46+
void Loop::_move(Source &from, Source &to) {
47+
for (auto &s : _sources) {
48+
if (s.source == &from)
49+
s.source = &to;
50+
}
51+
}
52+
53+
void Loop::_dtor(Source *source) {
54+
for (auto &s : _sources) {
55+
if (s.source == source)
56+
s.source = nullptr;
57+
}
58+
}
59+
60+
/* --- Public --- */
61+
62+
void Loop::_collect() {
63+
for (usize i = 0; i < _sources.len(); i++) {
64+
auto [source, sink] = _sources[i];
65+
if (not source or not sink) {
66+
_sources.removeAt(i--);
67+
}
68+
}
69+
}
70+
71+
Res<TimeStamp> Loop::poll() {
72+
TimeStamp until = TimeStamp::endOfTime();
73+
74+
for (usize i = 0; i < _sources.len(); i++) {
75+
auto [source, sink] = _sources[i];
76+
if (not source or not sink)
77+
continue;
78+
79+
auto ts = try$(source->poll(*sink));
80+
81+
if (Op::lt(ts, until))
82+
until = ts;
83+
}
84+
85+
return Ok(until);
86+
}
87+
88+
Res<usize> Loop::dispatch() {
89+
usize count = 0;
90+
for (usize i = 0; i < _queued.len(); i++) {
91+
count++;
92+
auto *target = _queued[i].sink;
93+
auto event = std::move(_queued[i].event);
94+
95+
if (not target)
96+
continue;
97+
98+
auto res = target->post(*event);
99+
if (not res) {
100+
_queued.removeRange(0, i);
101+
return res.none();
102+
}
103+
}
104+
105+
_queued.clear();
106+
return Ok(count);
107+
}
108+
109+
Res<> Loop::run() {
110+
while (true) {
111+
debug(" --- Loop ---");
112+
usize count = 0;
113+
TimeStamp until = TimeStamp::endOfTime();
114+
115+
do {
116+
until = try$(poll());
117+
count = try$(dispatch());
118+
_collect();
119+
} while (count);
120+
121+
if (_sources.len() == 0)
122+
return Ok();
123+
124+
if (_ret)
125+
return *_ret;
126+
127+
try$(wait(until));
128+
}
129+
}
130+
131+
} // namespace Karm::Async

0 commit comments

Comments
 (0)