zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    解决iex -S mix报错
    OTP服务器
    多进程
    字符串与二进制
    IphoneX适配正确姿势
    Babel 配置用法解析
    babel版本变化
    你好,babel
    XSS攻击 && CSRF攻击 基础理解
    小程序开发初体验~
  • 原文地址:https://www.cnblogs.com/linbc/p/1900701.html
Copyright © 2011-2022 走看看