1
This commit is contained in:
parent
903d7d9b56
commit
806ec31e24
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
13
a8/xtimer.cc
13
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)
|
||||
{
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
struct xtvec_base;
|
||||
namespace a8
|
||||
{
|
||||
typedef std::function<void(int, const a8::Args*)> 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user