Skip to content

Commit

Permalink
Merge pull request #46 from vbirds/v2
Browse files Browse the repository at this point in the history
感谢修复
  • Loading branch information
owent authored Apr 3, 2023
2 parents 876bcee + 923810e commit 69ed252
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
24 changes: 22 additions & 2 deletions include/libcotask/task_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,17 @@ class LIBCOPP_COTASK_API_HEAD_ONLY task_manager<task<TCO_MACRO>> {
real_checkpoints.insert(new_checkpoint);
}

task_timeout_timer_.swap(task_timeout_timer_);
task_timeout_timer_.swap(real_checkpoints);
for (typename std::set<detail::task_timer_node<id_type>>::iterator iter = task_timeout_timer_.begin();
task_timeout_timer_.end() != iter; ++iter) {
const typename std::set<detail::task_timer_node<id_type>>::value_type &checkpoint = *iter;
using co_iter_type = typename container_type::iterator;
co_iter_type co_iter = tasks_.find(checkpoint.task_id);

if (tasks_.end() != co_iter) {
co_iter->second.timer_node = iter;
}
}
last_tick_time_ = now_tick_time;
return LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_SUCCESS;
}
Expand Down Expand Up @@ -1307,7 +1317,17 @@ class LIBCOPP_COTASK_API_HEAD_ONLY task_manager<task_future<TVALUE, TPRIVATE_DAT
real_checkpoints.insert(new_checkpoint);
}

task_timeout_timer_.swap(task_timeout_timer_);
task_timeout_timer_.swap(real_checkpoints);
for (typename std::set<detail::task_timer_node<id_type>>::iterator iter = task_timeout_timer_.begin();
task_timeout_timer_.end() != iter; ++iter) {
const typename std::set<detail::task_timer_node<id_type>>::value_type &checkpoint = *iter;
using co_iter_type = typename container_type::iterator;
co_iter_type co_iter = tasks_.find(checkpoint.task_id);

if (tasks_.end() != co_iter) {
co_iter->second.timer_node = iter;
}
}
last_tick_time_ = now_tick_time;
return LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_SUCCESS;
}
Expand Down
10 changes: 6 additions & 4 deletions test/case/coroutine_task_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,20 @@ CASE_TEST(coroutine_task_manager, add_and_timeout) {
task_mgr->tick(3);
CASE_EXPECT_EQ(2, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());

task_mgr->tick(8);
CASE_EXPECT_EQ(8, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_checkpoints().size());
// tick reset timeout: 3 + 5 = 8
CASE_EXPECT_EQ(8, (int)task_mgr->get_container().find(co_task->get_id())->second.timer_node->expired_time.tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_checkpoints().size());
CASE_EXPECT_FALSE(cotask::EN_TS_TIMEOUT == co_task->get_status());

task_mgr->tick(9);
CASE_EXPECT_EQ(9, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_container().size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_TRUE(cotask::EN_TS_TIMEOUT == co_task->get_status());

CASE_EXPECT_NE(co_task, task_mgr->find_task(co_task->get_id()));
CASE_EXPECT_EQ(co_another_task, task_mgr->find_task(co_another_task->get_id()));
Expand Down
41 changes: 26 additions & 15 deletions test/case/task_promise_task_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,22 @@ CASE_TEST(task_promise_task_manager, add_and_timeout) {

co_task.start();

CASE_EXPECT_EQ(3, (int)task_mgr->get_last_tick_time().tv_sec);
task_mgr->tick(8);
CASE_EXPECT_EQ(8, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_checkpoints().size());
// tick reset timeout: 3 + 5 = 8
CASE_EXPECT_EQ(8, (int)task_mgr->get_container().find(co_task.get_id())->second.timer_node->expired_time.tv_sec);
CASE_EXPECT_EQ(2, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_checkpoints().size());
CASE_EXPECT_FALSE(task_future_int_type::task_status_type::kTimeout == co_task.get_status());

task_mgr->tick(9);
CASE_EXPECT_EQ(9, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_container().size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_TRUE(task_future_int_type::task_status_type::kTimeout == co_task.get_status());

CASE_EXPECT_EQ(nullptr, task_mgr->find_task(co_task.get_id()));
CASE_EXPECT_TRUE(co_another_task == *task_mgr->find_task(co_another_task.get_id()));
Expand Down Expand Up @@ -240,20 +245,22 @@ CASE_TEST(task_promise_task_manager, add_and_timeout_no_start) {

CASE_EXPECT_EQ(0, (int)task_mgr->get_last_tick_time().tv_sec);
task_mgr->tick(3);
CASE_EXPECT_EQ(2, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());

CASE_EXPECT_EQ(3, (int)task_mgr->get_last_tick_time().tv_sec);
task_mgr->tick(8);
CASE_EXPECT_EQ(8, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_checkpoints().size());
// tick reset timeout: 3 + 5 = 8
CASE_EXPECT_EQ(8, (int)task_mgr->get_container().find(co_task.get_id())->second.timer_node->expired_time.tv_sec);
CASE_EXPECT_EQ(2, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_checkpoints().size());
CASE_EXPECT_FALSE(task_future_int_type::task_status_type::kTimeout == co_task.get_status());

task_mgr->tick(9);
CASE_EXPECT_EQ(9, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_container().size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_TRUE(task_future_int_type::task_status_type::kTimeout == co_task.get_status());

CASE_EXPECT_EQ(nullptr, task_mgr->find_task(co_task.get_id()));
CASE_EXPECT_TRUE(co_another_task == *task_mgr->find_task(co_another_task.get_id()));
Expand Down Expand Up @@ -294,6 +301,7 @@ CASE_TEST(task_promise_task_manager, add_and_timeout_last_reference) {
mgr_t::ptr_type task_mgr = mgr_t::create();

task_future_int_type::id_type another_task_id;
task_future_int_type::id_type task_id;
{
task_future_int_type co_task = task_func_await_int();
task_future_int_type co_another_task = task_func_await_int();
Expand All @@ -302,6 +310,7 @@ CASE_TEST(task_promise_task_manager, add_and_timeout_last_reference) {

co_task.start();
another_task_id = co_another_task.get_id();
task_id = co_task.get_id();

task_mgr->add_task(std::move(co_task), 5, 0);
task_mgr->add_task(std::move(co_another_task));
Expand All @@ -312,20 +321,22 @@ CASE_TEST(task_promise_task_manager, add_and_timeout_last_reference) {

CASE_EXPECT_EQ(0, (int)task_mgr->get_last_tick_time().tv_sec);
task_mgr->tick(3);
CASE_EXPECT_EQ(2, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());

CASE_EXPECT_EQ(3, (int)task_mgr->get_last_tick_time().tv_sec);
task_mgr->tick(8);
CASE_EXPECT_EQ(8, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_checkpoints().size());
// tick reset timeout: 3 + 5 = 8
CASE_EXPECT_EQ(8, (int)task_mgr->get_container().find(task_id)->second.timer_node->expired_time.tv_sec);
CASE_EXPECT_EQ(2, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_checkpoints().size());
CASE_EXPECT_FALSE(nullptr == task_mgr->find_task(task_id));

task_mgr->tick(9);
CASE_EXPECT_EQ(9, (int)task_mgr->get_last_tick_time().tv_sec);
CASE_EXPECT_EQ(1, (int)task_mgr->get_task_size());
CASE_EXPECT_EQ(1, (int)task_mgr->get_container().size());
CASE_EXPECT_EQ(0, (int)task_mgr->get_tick_checkpoint_size());
CASE_EXPECT_EQ(nullptr, task_mgr->find_task(task_id));

CASE_EXPECT_EQ(old_resume_generator_count + 1, g_task_manager_future_resume_generator_count);
CASE_EXPECT_EQ(old_suspend_generator_count + 1, g_task_manager_future_suspend_generator_count);
Expand Down

0 comments on commit 69ed252

Please sign in to comment.