From 806ec31e24a6639ca615510cc420f90a3f59ff41 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 13 Dec 2022 18:38:53 +0800 Subject: [PATCH] 1 --- a8/ioloop.cc | 4 ++-- a8/timer_attacher.cc | 10 +++++----- a8/xtimer.cc | 13 ++++++++----- a8/xtimer.h | 4 ++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/a8/ioloop.cc b/a8/ioloop.cc index b6aac91..2a1c3d0 100644 --- a/a8/ioloop.cc +++ b/a8/ioloop.cc @@ -107,7 +107,7 @@ namespace a8 { AsyncTcpClient* client = new AsyncTcpClient(); IoLoopThreadContext* thread_context = thread_contexts_[(uintptr_t)client % thread_num_]; - client->connect_timer_attacher.xtimer = &thread_context->xtimer; + client->connect_timer_attacher.SetOwner(&thread_context->xtimer); client->SetEpollFd(thread_context->epoll_fd); return client; } @@ -265,7 +265,7 @@ namespace a8 AsyncTcpClient* client = (AsyncTcpClient*)param.sender.GetUserData(); client->DoAsyncConnect(); client->connect_timer_attacher.ClearTimerList(); - context->xtimer.AddDeadLineTimer + context->xtimer.SetTimeoutEx ( param.param1, [client] (int event, const a8::Args* args) diff --git a/a8/timer_attacher.cc b/a8/timer_attacher.cc index 5fe8a31..b77cb0b 100644 --- a/a8/timer_attacher.cc +++ b/a8/timer_attacher.cc @@ -27,19 +27,19 @@ namespace a8 } } - XTimerAttacher::XTimerAttacher() + Attacher::Attacher() { INIT_LIST_HEAD(&timer_list_); } - XTimerAttacher::~XTimerAttacher() + Attacher::~Attacher() { - xtimer->DestoryAttacher(this); + owner_->DestoryAttacher(this); } - void XTimerAttacher::ClearTimerList() + void Attacher::ClearTimerList() { - xtimer->ClearAttacher(this); + owner_->ClearAttacher(this); } } diff --git a/a8/xtimer.cc b/a8/xtimer.cc index 873fce3..4e238a3 100644 --- a/a8/xtimer.cc +++ b/a8/xtimer.cc @@ -43,7 +43,7 @@ struct xtimer_list { int fixed_timer_execute_times; struct xtvec_base *base; - a8::TimerCbProc cb; + a8::TimerCb cb; }; struct XTimerDestoryHandleNode @@ -105,7 +105,7 @@ static inline int DetachTimer(struct xtimer_list *timer) static inline void InitTimerList(xtvec_base* base, xtimer_list* timer, int timer_type, long long expires, int expire_time, - a8::TimerCbProc cb) + a8::TimerCb cb) { INIT_LIST_HEAD(&timer->destory_handle_list); INIT_LIST_HEAD(&timer->entry); @@ -130,7 +130,7 @@ static xtimer_list* NewTimerList(xtvec_base* base_) } } -static AddToFreeList(xtvec_base* base_, xtimer_list* timer) +static void AddToFreeList(xtvec_base* base_, xtimer_list* timer) { list_add_tail(&timer->entry, &base_->free_timer); base_->free_timer_num++; @@ -163,7 +163,9 @@ namespace a8 XTimer::~XTimer() { +#if 0 Clear(); +#endif delete base_; base_ = nullptr; } @@ -175,7 +177,7 @@ namespace a8 gc_time_ = gc_time; cache_timer_num_ = cache_timer_num; base_->timer_tick = get_tick_count_func_(context_); - AddRepeatTimer + SetInterval (gc_time_, [this] (int event, const a8::Args* args) { @@ -201,6 +203,7 @@ namespace a8 } } + #if 0 void XTimer::AddDeadLineTimer( int expire_time, a8::TimerCbProc timer_cb, @@ -501,7 +504,7 @@ namespace a8 } base->running_timer = nullptr; } - +#endif void XTimer::SetTimeout(int time, TimerCb cb) { diff --git a/a8/xtimer.h b/a8/xtimer.h index ab69df0..bb50063 100644 --- a/a8/xtimer.h +++ b/a8/xtimer.h @@ -1,5 +1,6 @@ #pragma once +struct xtvec_base; namespace a8 { typedef std::function TimerCb; @@ -36,9 +37,8 @@ namespace a8 void UpdateTimer(); void ClearAttacher(Attacher* attacher); void DestoryAttacher(Attacher* attacher); - private: - struct xtvec_base* base_ = nullptr; + xtvec_base* base_ = nullptr; XGetTickCountFunc get_tick_count_func_ = nullptr; void* context_ = nullptr; int gc_time_ = 10;