forked from guoxuanhan/NetServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
44 lines (39 loc) · 945 Bytes
/
timer.cpp
File metadata and controls
44 lines (39 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <sys/time.h>
#include "timer.h"
#include "timermanager.h"
Timer::Timer(int timeout, TimerType timertype, const CallBack &timercallback) :
timeout_(timeout),
timertype_(timertype),
timercallback_(timercallback),
rotation(0),
timeslot(0),
prev(nullptr),
next(nullptr)
{
if(timeout < 0)
{
return;
}
// struct timeval tv;
// gettimeofday(&tv, NULL);
// timeout_ = (tv.tv_sec % 10000) * 1000 + tv.tv_usec / 1000 + timeout;
}
Timer::~Timer()
{
Stop();
}
void Timer::Start()
{
TimerManager::GetTimerManagerInstance()->AddTimer(this);
}
void Timer::Stop()
{
TimerManager::GetTimerManagerInstance()->RemoveTimer(this);
}
void Timer::Adjust(int timeout, Timer::TimerType timertype, const CallBack &timercallback)
{
timeout_ = timeout;
timertype_ = timertype;
timercallback_ = timercallback;
TimerManager::GetTimerManagerInstance()->AdjustTimer(this);
}