arm: more uart async & debug stuff
This commit is contained in:
58
arm/async.h
58
arm/async.h
@@ -30,6 +30,64 @@ struct task_final_suspend {
|
||||
std::coroutine_handle<> parent;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct gimme {
|
||||
// child interface
|
||||
bool await_ready() { return false; }
|
||||
void await_suspend(std::coroutine_handle<> h) {
|
||||
ha = h;
|
||||
waiting = true;
|
||||
TRACE(tracing::TraceEvent::kAsyncGimmeWaiting);
|
||||
|
||||
if (parent) {
|
||||
TRACE(tracing::TraceEvent::kAsyncCallParent);
|
||||
parent.resume();
|
||||
TRACE(tracing::TraceEvent::kAsyncCallParentDone);
|
||||
}
|
||||
}
|
||||
T await_resume() {
|
||||
waiting = false;
|
||||
TRACE(tracing::TraceEvent::kAsyncGimmeResume);
|
||||
return std::move(stuff);
|
||||
}
|
||||
|
||||
// parent interface
|
||||
auto feed(T&& s) {
|
||||
struct awaitable {
|
||||
bool await_ready() {
|
||||
if (g.waiting) {
|
||||
return true;
|
||||
}
|
||||
// TODO: handle g.ha.done()
|
||||
return false;
|
||||
}
|
||||
void await_suspend(std::coroutine_handle<> h) {
|
||||
g.parent = h;
|
||||
}
|
||||
void await_resume() {}
|
||||
|
||||
gimme<T>& g;
|
||||
};
|
||||
|
||||
if (!waiting) {
|
||||
__builtin_trap();
|
||||
}
|
||||
if (!ha) {
|
||||
__builtin_trap();
|
||||
}
|
||||
stuff = s;
|
||||
parent = {};
|
||||
ha.resume();
|
||||
|
||||
return awaitable{.g = *this};
|
||||
}
|
||||
|
||||
bool waiting = false;
|
||||
std::coroutine_handle<> ha;
|
||||
T stuff;
|
||||
std::coroutine_handle<> parent;
|
||||
};
|
||||
|
||||
template <typename T = void>
|
||||
struct task;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user