基于多线程的event engine以及多进程通信库实现(三)
Timer实现
class cESTimer:public cESTime,public cESEvent
{
public:
cESTimer():cESTime(),
cESEvent(TIMER_EVENT_TYPE,
TIMER_EVENT_PRIORITY,
DO_ACTION_IN_MAINTHREAD,
"Timer event")
#ifdef _DEBUG
//,time(::GetTickCount())
#endif
,timer_done(false)
,post_cnt(0)
{
//#ifdef _DEBUG
time = ::GetTickCount();
//#endif
}
~cESTimer(){ cout<<"In __________~cESTimer()_________"<
bool update(void);//must return bool because of for_each
void reset(void);
void set(cESTime&);
bool get_timer_status(void)const{ return timer_done; }
virtual void do_action(void);
virtual VOID thread_function(VOID){}
cESSycObject timer_done_lock;
protected:
/*
* For testing
*/
volatile long time;
};
Timer Manager实现
class cESTimerManager:public cESThread{
public:
~cESTimerManager();
static cESTimerManager* instance(void);
void init(void);
void start(void);
void stop(void);
bool del_timer(cESTimer*);
void add_timer(cESTimer*);
void clear_all_timer(void);
void notify_timer_evt(void);
void update(void);
}
virtual void thread_function(void);
private:
cESTimerManager();
static cESTimerManager* p_timer_manager;
protected:
static timer_list_t timer_list;
#ifdef WINDOWS_H
static cESSycObject timer_list_lock;
#endif
};
阅读(2026) | 评论(0) | 转发(0) |