Chinaunix首页 | 论坛 | 博客
  • 博客访问: 827337
  • 博文数量: 168
  • 博客积分: 5431
  • 博客等级: 大校
  • 技术积分: 1560
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-22 11:56
文章存档

2015年(2)

2014年(1)

2013年(12)

2012年(12)

2011年(15)

2010年(5)

2009年(16)

2008年(41)

2007年(64)

分类: C/C++

2008-07-20 22:05:09

基于多线程的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
   
};



阅读(1993) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~