From a3c22feb24498ab0d973862322061f66bb37fb80 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 18 May 2023 22:50:06 +0800 Subject: [PATCH] 1 --- server/robotserver/comgr.cc | 2 +- server/robotserver/coroutine.cc | 12 ++++++------ server/robotserver/coroutine.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/robotserver/comgr.cc b/server/robotserver/comgr.cc index f66d4e04..9a5d1e1d 100644 --- a/server/robotserver/comgr.cc +++ b/server/robotserver/comgr.cc @@ -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; } diff --git a/server/robotserver/coroutine.cc b/server/robotserver/coroutine.cc index a5cf55e3..b383dfc1 100644 --- a/server/robotserver/coroutine.cc +++ b/server/robotserver/coroutine.cc @@ -7,7 +7,7 @@ Coroutine::Coroutine(std::function cb) { - INIT_LIST_HEAD(&entry); + INIT_LIST_HEAD(&exec_entry_); cb_ = cb; source_ = std::make_shared::pull_type> ( @@ -17,14 +17,14 @@ Coroutine::Coroutine(std::function 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_); } } diff --git a/server/robotserver/coroutine.h b/server/robotserver/coroutine.h index d6ccdbac..410b2601 100644 --- a/server/robotserver/coroutine.h +++ b/server/robotserver/coroutine.h @@ -15,12 +15,9 @@ class Promise : public Awaiter class Coroutine : public Awaiter, public std::enable_shared_from_this { public: - list_head entry; - Coroutine(std::function cb); ~Coroutine(); - bool Exec(); void CoSuspend(); void CoResume(); void CoYield(); @@ -29,12 +26,15 @@ class Coroutine : public Awaiter, public std::enable_shared_from_this private: + bool Exec(); void Attach(); void Deatch(); void CallEnter(boost::coroutines2::coroutine::push_type& sink); void CallExit(boost::coroutines2::coroutine::push_type& sink); private: + list_head co_entry_; + list_head exec_entry_; std::shared_ptr hold_self_; std::shared_ptr::pull_type> source_; std::function cb_;