forked from jimingmin/frame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_timermgt.h
73 lines (53 loc) · 1.69 KB
/
frame_timermgt.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* frame_timermgt.h
*
* Created on: 2014年1月22日
* Author: jimm
*/
#ifndef FRAME_TIMERMGT_H_
#define FRAME_TIMERMGT_H_
#include "common/common_object.h"
#include "common/common_pool.h"
#include "common/common_rbtree.h"
#include "common/common_mutex.h"
#include "common/common_runnable.h"
#include "frame_impl.h"
#include "frame_timer.h"
#include "frame_namespace.h"
FRAME_NAMESPACE_BEGIN
#define MAX_TIMER_COUNT 100000 //定时器个数
typedef CPool<CTimer, MAX_TIMER_COUNT> TimerPool;
typedef CRBTree<int64_t, TimerIndex, MAX_TIMER_COUNT> TimerMap;
class CTimerMgt : public CBaseObject, public IRunnable
{
protected:
enum
{
enmAdditionalIndex_RBTreeIndex = 0,
};
public:
CTimerMgt();
virtual ~CTimerMgt();
virtual int32_t Init();
virtual int32_t Uninit();
virtual int32_t GetSize();
virtual int32_t Run();
int32_t CreateTimer(TimerProc Proc, CBaseObject *pTimer, CBaseObject *pTimerData, int64_t nCycleTime, bool bLoop, TimerIndex& timerIndex);
int32_t RemoveTimer(TimerIndex timerIndex);
int32_t Clear();
int32_t TimerFired(TimerIndex timerIndex, uint32_t timerSeq);
int32_t GetFirstTimer(CTimer*& pTimer, TimerIndex& timerIndex);
int32_t GetTimer(TimerIndex timerIndex, CTimer*& pTimer);
int32_t RemoveTimer(TimerPool::CIndex* pIndex);
int32_t TimerFired(TimerIndex timerIndex);
int32_t GetFirstTimer(TimerPool::CIndex*& pIndex);
protected:
uint32_t m_nTimerSeq;
CriticalSection m_stTimerLock;
// CriticalSection m_stTimerPoolLock;
TimerPool m_timerPool;
// CriticalSection m_stTimerMapLock;
TimerMap m_timerMap;
};
FRAME_NAMESPACE_END
#endif /* FRAME_TIMERMGT_H_ */