-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathydx_timer.h
50 lines (37 loc) · 927 Bytes
/
ydx_timer.h
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
45
46
47
48
49
50
#ifndef __YDX_TIMER_H__
#define __YDX_TIMER_H__
#include <boost/noncopyable.hpp>
#include "timestamp.h"
#include "callback_types.h"
#include "ydx_atomic.h"
namespace ydx
{
class Timer : boost::noncopyable
{
public:
Timer(const TimerCallback &cb, Timestamp when, double interval)
: timer_func_(cb),
expiration_(when),
interval_(interval),
repeat_(interval > 0.0),
sequence_(timer_sequence_creater.incrementAndGet())
{}
void run() const
{
timer_func_();
}
Timestamp expiration() const { return expiration_; }
bool repeat() const {return repeat_; }
int64_t sequence() const {return sequence_; }
void restart(Timestamp now);
static int64_t index_create() {return timer_sequence_creater.get();}
private:
const TimerCallback timer_func_;
Timestamp expiration_;
const double interval_;
const bool repeat_;
const int64_t sequence_;
static AtomicInt64 timer_sequence_creater;
};
}
#endif