mirror of https://github.com/RainMark/cops.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
488 B
28 lines
488 B
#include <context.h>
|
|
#include <iostream>
|
|
|
|
namespace cops{
|
|
|
|
static coro_t def([](){});
|
|
coro_t* current = &def;
|
|
|
|
void main(coro_t* coro, context from) {
|
|
coro->next_->ctx_ = from;
|
|
coro->fn_();
|
|
coro->switch_out();
|
|
}
|
|
|
|
void coro_t::switch_out() {
|
|
current = next_;
|
|
context from = switch_context(next_, next_->ctx_);
|
|
next_ = static_cast<coro_t*>(from);
|
|
next_->ctx_ = from;
|
|
}
|
|
|
|
void coro_t::switch_in() {
|
|
next_ = current;
|
|
current = this;
|
|
ctx_ = switch_context(this, ctx_);
|
|
}
|
|
|
|
}
|
|
|