1
This commit is contained in:
parent
903d7d9b56
commit
806ec31e24
@ -107,7 +107,7 @@ namespace a8
|
|||||||
{
|
{
|
||||||
AsyncTcpClient* client = new AsyncTcpClient();
|
AsyncTcpClient* client = new AsyncTcpClient();
|
||||||
IoLoopThreadContext* thread_context = thread_contexts_[(uintptr_t)client % thread_num_];
|
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);
|
client->SetEpollFd(thread_context->epoll_fd);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ namespace a8
|
|||||||
AsyncTcpClient* client = (AsyncTcpClient*)param.sender.GetUserData();
|
AsyncTcpClient* client = (AsyncTcpClient*)param.sender.GetUserData();
|
||||||
client->DoAsyncConnect();
|
client->DoAsyncConnect();
|
||||||
client->connect_timer_attacher.ClearTimerList();
|
client->connect_timer_attacher.ClearTimerList();
|
||||||
context->xtimer.AddDeadLineTimer
|
context->xtimer.SetTimeoutEx
|
||||||
(
|
(
|
||||||
param.param1,
|
param.param1,
|
||||||
[client] (int event, const a8::Args* args)
|
[client] (int event, const a8::Args* args)
|
||||||
|
@ -27,19 +27,19 @@ namespace a8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XTimerAttacher::XTimerAttacher()
|
Attacher::Attacher()
|
||||||
{
|
{
|
||||||
INIT_LIST_HEAD(&timer_list_);
|
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;
|
int fixed_timer_execute_times;
|
||||||
struct xtvec_base *base;
|
struct xtvec_base *base;
|
||||||
|
|
||||||
a8::TimerCbProc cb;
|
a8::TimerCb cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct XTimerDestoryHandleNode
|
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,
|
static inline void InitTimerList(xtvec_base* base, xtimer_list* timer, int timer_type,
|
||||||
long long expires, int expire_time,
|
long long expires, int expire_time,
|
||||||
a8::TimerCbProc cb)
|
a8::TimerCb cb)
|
||||||
{
|
{
|
||||||
INIT_LIST_HEAD(&timer->destory_handle_list);
|
INIT_LIST_HEAD(&timer->destory_handle_list);
|
||||||
INIT_LIST_HEAD(&timer->entry);
|
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);
|
list_add_tail(&timer->entry, &base_->free_timer);
|
||||||
base_->free_timer_num++;
|
base_->free_timer_num++;
|
||||||
@ -163,7 +163,9 @@ namespace a8
|
|||||||
|
|
||||||
XTimer::~XTimer()
|
XTimer::~XTimer()
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
Clear();
|
Clear();
|
||||||
|
#endif
|
||||||
delete base_;
|
delete base_;
|
||||||
base_ = nullptr;
|
base_ = nullptr;
|
||||||
}
|
}
|
||||||
@ -175,7 +177,7 @@ namespace a8
|
|||||||
gc_time_ = gc_time;
|
gc_time_ = gc_time;
|
||||||
cache_timer_num_ = cache_timer_num;
|
cache_timer_num_ = cache_timer_num;
|
||||||
base_->timer_tick = get_tick_count_func_(context_);
|
base_->timer_tick = get_tick_count_func_(context_);
|
||||||
AddRepeatTimer
|
SetInterval
|
||||||
(gc_time_,
|
(gc_time_,
|
||||||
[this] (int event, const a8::Args* args)
|
[this] (int event, const a8::Args* args)
|
||||||
{
|
{
|
||||||
@ -201,6 +203,7 @@ namespace a8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void XTimer::AddDeadLineTimer(
|
void XTimer::AddDeadLineTimer(
|
||||||
int expire_time,
|
int expire_time,
|
||||||
a8::TimerCbProc timer_cb,
|
a8::TimerCbProc timer_cb,
|
||||||
@ -501,7 +504,7 @@ namespace a8
|
|||||||
}
|
}
|
||||||
base->running_timer = nullptr;
|
base->running_timer = nullptr;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
void XTimer::SetTimeout(int time, TimerCb cb)
|
void XTimer::SetTimeout(int time, TimerCb cb)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
struct xtvec_base;
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
typedef std::function<void(int, const a8::Args*)> TimerCb;
|
typedef std::function<void(int, const a8::Args*)> TimerCb;
|
||||||
@ -36,9 +37,8 @@ namespace a8
|
|||||||
void UpdateTimer();
|
void UpdateTimer();
|
||||||
void ClearAttacher(Attacher* attacher);
|
void ClearAttacher(Attacher* attacher);
|
||||||
void DestoryAttacher(Attacher* attacher);
|
void DestoryAttacher(Attacher* attacher);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct xtvec_base* base_ = nullptr;
|
xtvec_base* base_ = nullptr;
|
||||||
XGetTickCountFunc get_tick_count_func_ = nullptr;
|
XGetTickCountFunc get_tick_count_func_ = nullptr;
|
||||||
void* context_ = nullptr;
|
void* context_ = nullptr;
|
||||||
int gc_time_ = 10;
|
int gc_time_ = 10;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user