This commit is contained in:
aozhiwei 2023-05-18 23:00:34 +08:00
parent 2ddbc831ec
commit 97fb0f0aa6
3 changed files with 16 additions and 11 deletions

View File

@ -7,6 +7,20 @@ void CoMgr::Init()
{ {
INIT_LIST_HEAD(&co_list_); INIT_LIST_HEAD(&co_list_);
INIT_LIST_HEAD(&exec_list_); INIT_LIST_HEAD(&exec_list_);
CreateCo
(
[] (Coroutine* co)
{
a8::XPrintf("call 1\n", {});
a8::XPrintf("call 2\n", {});
});
CreateCo
(
[] (Coroutine* co)
{
a8::XPrintf("call 10\n", {});
a8::XPrintf("call 11\n", {});
});
} }
void CoMgr::UnInit() void CoMgr::UnInit()
@ -26,7 +40,7 @@ void CoMgr::Update()
std::weak_ptr<Coroutine> CoMgr::CreateCo(std::function<void(Coroutine*)> cb) std::weak_ptr<Coroutine> CoMgr::CreateCo(std::function<void(Coroutine*)> cb)
{ {
auto co = std::make_shared<Coroutine>(cb); std::shared_ptr<Coroutine> co(new Coroutine(cb));
co->hold_self_ = co; co->hold_self_ = co;
return co; return co;
} }

View File

@ -15,7 +15,6 @@ class Promise : public Awaiter
class Coroutine : public Awaiter, public std::enable_shared_from_this<Coroutine> class Coroutine : public Awaiter, public std::enable_shared_from_this<Coroutine>
{ {
public: public:
Coroutine(std::function<void(Coroutine*)> cb);
~Coroutine(); ~Coroutine();
void CoSuspend(); void CoSuspend();
@ -25,6 +24,7 @@ class Coroutine : public Awaiter, public std::enable_shared_from_this<Coroutine>
void CoAwait(Awaiter* awaiter); void CoAwait(Awaiter* awaiter);
private: private:
Coroutine(std::function<void(Coroutine*)> cb);
bool Exec(); bool Exec();
void Attach(); void Attach();

View File

@ -13,15 +13,6 @@
void PlayerMgr::Init() void PlayerMgr::Init()
{ {
for (int i = 0; i < 10; i++) {
}
Coroutine co
(
[] (Coroutine* co)
{
});
} }
void PlayerMgr::UnInit() void PlayerMgr::UnInit()