修复timer泄漏问题
This commit is contained in:
parent
bc1e1e002c
commit
8b113606e3
29
a8/timer.cc
29
a8/timer.cc
@ -148,6 +148,9 @@ namespace a8
|
|||||||
|
|
||||||
void Timer::UnInit()
|
void Timer::UnInit()
|
||||||
{
|
{
|
||||||
|
Clear();
|
||||||
|
delete base_;
|
||||||
|
base_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::Update()
|
void Timer::Update()
|
||||||
@ -332,6 +335,32 @@ namespace a8
|
|||||||
base_->free_timer_num++;
|
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)
|
void Timer::GC_TimerFunc(const a8::XParams& param)
|
||||||
{
|
{
|
||||||
Timer* timer = (Timer*)param.sender.GetUserData();
|
Timer* timer = (Timer*)param.sender.GetUserData();
|
||||||
|
@ -47,6 +47,7 @@ namespace a8
|
|||||||
void UpdateTimer();
|
void UpdateTimer();
|
||||||
timer_list* NewTimerList();
|
timer_list* NewTimerList();
|
||||||
void AddToFreeList(timer_list* timer);
|
void AddToFreeList(timer_list* timer);
|
||||||
|
void Clear();
|
||||||
static void GC_TimerFunc(const a8::XParams& param);
|
static void GC_TimerFunc(const a8::XParams& param);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user