1
This commit is contained in:
parent
93c3442442
commit
a3c22feb24
@ -17,7 +17,7 @@ void CoMgr::UnInit()
|
||||
void CoMgr::Update()
|
||||
{
|
||||
Coroutine *co = nullptr, *tmp = nullptr;
|
||||
list_for_each_entry_safe(co, tmp, &co_list_, entry) {
|
||||
list_for_each_entry_safe(co, tmp, &co_list_, exec_entry_) {
|
||||
if (!co->Exec()) {
|
||||
co->hold_self_ = nullptr;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
Coroutine::Coroutine(std::function<void(Coroutine*)> cb)
|
||||
{
|
||||
INIT_LIST_HEAD(&entry);
|
||||
INIT_LIST_HEAD(&exec_entry_);
|
||||
cb_ = cb;
|
||||
source_ = std::make_shared<boost::coroutines2::coroutine<void>::pull_type>
|
||||
(
|
||||
@ -17,14 +17,14 @@ Coroutine::Coroutine(std::function<void(Coroutine*)> cb)
|
||||
cb_(this);
|
||||
CallExit(sink);
|
||||
});
|
||||
list_add_tail(&entry, &CoMgr::Instance()->co_list_);
|
||||
list_add_tail(&co_entry_, &CoMgr::Instance()->co_list_);
|
||||
Attach();
|
||||
}
|
||||
|
||||
Coroutine::~Coroutine()
|
||||
{
|
||||
Deatch();
|
||||
list_del_init(&entry);
|
||||
list_del_init(&co_entry_);
|
||||
}
|
||||
|
||||
bool Coroutine::Exec()
|
||||
@ -64,13 +64,13 @@ void Coroutine::CoAwait(Awaiter* awaiter)
|
||||
|
||||
void Coroutine::Attach()
|
||||
{
|
||||
list_add_tail(&entry, &CoMgr::Instance()->exec_list_);
|
||||
list_add_tail(&exec_entry_, &CoMgr::Instance()->exec_list_);
|
||||
}
|
||||
|
||||
void Coroutine::Deatch()
|
||||
{
|
||||
if (list_empty(&entry)) {
|
||||
list_del_init(&entry);
|
||||
if (list_empty(&exec_entry_)) {
|
||||
list_del_init(&exec_entry_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,9 @@ class Promise : public Awaiter
|
||||
class Coroutine : public Awaiter, public std::enable_shared_from_this<Coroutine>
|
||||
{
|
||||
public:
|
||||
list_head entry;
|
||||
|
||||
Coroutine(std::function<void(Coroutine*)> cb);
|
||||
~Coroutine();
|
||||
|
||||
bool Exec();
|
||||
void CoSuspend();
|
||||
void CoResume();
|
||||
void CoYield();
|
||||
@ -29,12 +26,15 @@ class Coroutine : public Awaiter, public std::enable_shared_from_this<Coroutine>
|
||||
|
||||
private:
|
||||
|
||||
bool Exec();
|
||||
void Attach();
|
||||
void Deatch();
|
||||
void CallEnter(boost::coroutines2::coroutine<void>::push_type& sink);
|
||||
void CallExit(boost::coroutines2::coroutine<void>::push_type& sink);
|
||||
|
||||
private:
|
||||
list_head co_entry_;
|
||||
list_head exec_entry_;
|
||||
std::shared_ptr<Coroutine> hold_self_;
|
||||
std::shared_ptr<boost::coroutines2::coroutine<void>::pull_type> source_;
|
||||
std::function<void(Coroutine* co)> cb_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user