修复timer泄漏问题
This commit is contained in:
parent
bc1e1e002c
commit
8b113606e3
31
a8/timer.cc
31
a8/timer.cc
@ -148,6 +148,9 @@ namespace a8
|
||||
|
||||
void Timer::UnInit()
|
||||
{
|
||||
Clear();
|
||||
delete base_;
|
||||
base_ = nullptr;
|
||||
}
|
||||
|
||||
void Timer::Update()
|
||||
@ -227,7 +230,7 @@ namespace a8
|
||||
if (!list_empty(&timer->attach_entry)) {
|
||||
list_del_init(&timer->attach_entry);
|
||||
}
|
||||
AddToFreeList(timer);
|
||||
AddToFreeList(timer);
|
||||
}
|
||||
|
||||
timer_list* Timer::GetTimerByAttach(list_head* attach_entry)
|
||||
@ -332,6 +335,32 @@ namespace a8
|
||||
base_->free_timer_num++;
|
||||
}
|
||||
|
||||
void Timer::Clear()
|
||||
{
|
||||
auto free_timers =
|
||||
[] (list_head* head)
|
||||
{
|
||||
while (!list_empty(head)) {
|
||||
struct timer_list *timer;
|
||||
timer = list_first_entry(head, struct timer_list,entry);
|
||||
DetachTimer(timer);
|
||||
if (!list_empty(&timer->attach_entry)) {
|
||||
list_del_init(&timer->attach_entry);
|
||||
}
|
||||
delete timer;
|
||||
}
|
||||
};
|
||||
for (int j = 0; j < TVN_SIZE; j++) {
|
||||
free_timers(base_->tv5.vec + j);
|
||||
free_timers(base_->tv4.vec + j);
|
||||
free_timers(base_->tv3.vec + j);
|
||||
free_timers(base_->tv2.vec + j);
|
||||
}
|
||||
for (int j = 0; j < TVR_SIZE; j++) {
|
||||
free_timers(base_->tv1.vec + j);
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::GC_TimerFunc(const a8::XParams& param)
|
||||
{
|
||||
Timer* timer = (Timer*)param.sender.GetUserData();
|
||||
|
@ -47,6 +47,7 @@ namespace a8
|
||||
void UpdateTimer();
|
||||
timer_list* NewTimerList();
|
||||
void AddToFreeList(timer_list* timer);
|
||||
void Clear();
|
||||
static void GC_TimerFunc(const a8::XParams& param);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user