Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Aug 9, 2023
1 parent 887fe71 commit e692910
Show file tree
Hide file tree
Showing 41 changed files with 1,104 additions and 133 deletions.
12 changes: 6 additions & 6 deletions meta/image/boot/loader.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"name": "Mobile",
"kernel": "bundle://hjert/_bin",
"blobs": [
"bundle://system-srv/_bin",
"bundle://device-srv/_bin",
"bundle://grund-system/_bin",
"bundle://grund-device/_bin",
{
"url": "bundle://hideo-shell/_bin",
"props": {
Expand All @@ -26,8 +26,8 @@
"name": "Desktop",
"kernel": "bundle://hjert/_bin",
"blobs": [
"bundle://system-srv/_bin",
"bundle://device-srv/_bin",
"bundle://grund-system/_bin",
"bundle://grund-device/_bin",
{
"url": "bundle://hideo-shell/_bin",
"props": {
Expand All @@ -41,8 +41,8 @@
"name": "Headless",
"kernel": "bundle://hjert/_bin",
"blobs": [
"bundle://system-srv/_bin",
"bundle://device-srv/_bin"
"bundle://grund-system/_bin",
"bundle://grund-device/_bin"
]
}
]
Expand Down
4 changes: 2 additions & 2 deletions meta/plugins/start-cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def bootCmd(args: Args) -> None:
image.installTo("loader", efiTarget, "EFI/BOOT/BOOTX64.EFI")
image.install("hjert", kernelTarget)
image.install("limine-tests", kernelTarget)
image.install("system-srv", skiftTarget)
image.install("device-srv", skiftTarget)
image.install("grund-system", skiftTarget)
image.install("grund-device", skiftTarget)
image.install("hideo-shell", skiftTarget)
image.install("skift-branding", skiftTarget)
image.install("skift-wallpapers", skiftTarget)
Expand Down
30 changes: 30 additions & 0 deletions src/impls/impl-posix/async.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <karm-async/async.h>
#include <karm-sys/proc.h>

namespace Karm::Async::_Embed {

struct PosixLoop : public Loop {
TimeStamp _now;

PosixLoop(TimeStamp now) : _now(now) {}

TimeStamp now() override {
return _now;
}

Res<> wait(TimeStamp until) override {
try$(Sys::sleepUntil(until));
_now = Sys::now();
return Ok();
}
};

static Opt<PosixLoop> _loop;
Loop &loop() {
if (not _loop) {
_loop.emplace(Sys::now());
}
return *_loop;
}

} // namespace Karm::Async::_Embed
5 changes: 5 additions & 0 deletions src/impls/impl-skift/async.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <karm-async/_embed.h>

namespace Karm::Async::_Embed {

} // namespace Karm::Async::_Embed
2 changes: 1 addition & 1 deletion src/kernel/hjert-core/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Res<> validateAndDump(u64 magic, Handover::Payload &payload) {
}

Res<> enterUserspace(Handover::Payload &payload) {
auto const *record = payload.fileByName("bundle://system-srv/_bin");
auto const *record = payload.fileByName("bundle://grund-system/_bin");
if (not record) {
logInfo("entry: handover: no init file");
return Error::invalidInput("No init file");
Expand Down
8 changes: 8 additions & 0 deletions src/libs/karm-async/_embed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace Karm::Async {
struct Loop;
namespace _Embed {
Loop &loop();
} // namespace _Embed
} // namespace Karm::Async
131 changes: 131 additions & 0 deletions src/libs/karm-async/async.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <karm-logger/logger.h>

#include "async.h"

namespace Karm::Async {

/* --- Sink --- */

void Loop::_post(Sink &sink, Box<Event> event) {
_queued.emplaceBack(sink, std::move(event));
}

void Loop::_move(Sink &from, Sink &to) {
logInfo("Moving sink from {p} to {p}", &from, &to);
for (auto &q : _queued) {
if (q.sink == &from) {
q.sink = &to;
}
}

for (auto &s : _sources) {
if (s.sink == &from) {
s.sink = &to;
}
}
}

void Loop::_dtor(Sink &sink) {
for (auto &q : _queued) {
if (q.sink == &sink)
q.sink = nullptr;
}

for (auto &s : _sources) {
if (s.sink == &sink)
s.sink = nullptr;
}
}

/* --- Source --- */

void Loop::_bind(Source &source, Sink &sink) {
_sources.emplaceBack(source, sink);
}

void Loop::_move(Source &from, Source &to) {
for (auto &s : _sources) {
if (s.source == &from)
s.source = &to;
}
}

void Loop::_dtor(Source *source) {
for (auto &s : _sources) {
if (s.source == source)
s.source = nullptr;
}
}

/* --- Public --- */

void Loop::_collect() {
for (usize i = 0; i < _sources.len(); i++) {
auto [source, sink] = _sources[i];
if (not source or not sink) {
_sources.removeAt(i--);
}
}
}

Res<TimeStamp> Loop::poll() {
TimeStamp until = TimeStamp::endOfTime();

for (usize i = 0; i < _sources.len(); i++) {
auto [source, sink] = _sources[i];
if (not source or not sink)
continue;

auto ts = try$(source->poll(*sink));

if (Op::lt(ts, until))
until = ts;
}

return Ok(until);
}

Res<usize> Loop::dispatch() {
usize count = 0;
for (usize i = 0; i < _queued.len(); i++) {
count++;
auto *target = _queued[i].sink;
auto event = std::move(_queued[i].event);

if (not target)
continue;

auto res = target->post(*event);
if (not res) {
_queued.removeRange(0, i);
return res.none();
}
}

_queued.clear();
return Ok(count);
}

Res<> Loop::run() {
while (true) {
debug(" --- Loop ---");
usize count = 0;
TimeStamp until = TimeStamp::endOfTime();

do {
until = try$(poll());
count = try$(dispatch());
_collect();
} while (count);

if (_sources.len() == 0)
return Ok();

if (_ret)
return *_ret;

try$(wait(until));
}
}

} // namespace Karm::Async
Loading

0 comments on commit e692910

Please sign in to comment.