• ACE定时器的用法


    分为三步

    1. 声明类型及实例
    2. 注册定时器
    3. 释放定时器
    typedef ACE_Thread_Timer_Queue_Adapter<ACE_Timer_Wheel> ActiveTimer;
     ActiveTimer timer;
     
    class CB:public ACE_Event_Handler
    {
    public:
        CB () : id_(0) { }
        virtual int handle_timeout (const ACE_Time_Value &tv,const void *arg)
        {
            //printf("Update\r\n");
            ((SessionManager *)arg)->Update(1);        
            return 0;
        }
        int id_;
    };
     
    //登记定时器
    void RegTimer()
    {
        //创建实例
        if(m_cb) delete m_cb;
        m_cb = new CB();
    
        //启动定时器线程
        m_atimer.activate ();
        const ACE_Time_Value curr_tv = ACE_OS::gettimeofday ();
        ACE_Time_Value interval1 = ACE_Time_Value (0, 1000000/8);//包处理时间
    
        //注册定时器
        m_cb->id_ = m_atimer.schedule (m_cb,     //event_handler 定时器会在指定时间间隔定时调用它的handle_timeout函数
            this,         //传入handle_timeout的参数
            curr_tv + ACE_Time_Value (3L),  //起始时间
            interval1);             //循环时间间隔
        ACE_Thread_Manager::instance ()->wait ();  // Wait forever.
    }
    //去掉定时器
    void UnRegTimer()
    {
        if(m_cb){
            m_atimer.cancel(m_cb->id_);
            delete m_cb;
            m_cb = NULL;
        }
    }
  • 相关阅读:
    Git 学习笔记(W,I,P)
    DirectX API 编程起步 #01 项目设置
    #1004 Let the Balloon Rise
    #1003 Max Sum
    人生的第一个博客(●'◡'●)ノ♥--开博典礼
    2053——switch game
    在Activity间传递数据的四种方法及返回结果
    安卓学习第38课——ProgressDialog
    安卓学习第37课——DatePickerDialog、TimePickerDialog
    安卓学习第36课——PopupWindow
  • 原文地址:https://www.cnblogs.com/linbc/p/1900701.html
Copyright © 2020-2023  润新知