• src/lib/framework/src/driverFramework.cpp学习



    1. int Framework::initialize()
    2. {
    3.     DF_LOG_DEBUG("Framework::initialize");

    4.     g_framework = new SyncObj;                                                    //这个应该是各同步类

    5.     if (!g_framework) {
    6.         DF_LOG_ERR("ERROR: falled to allocate g_framework");
    7.         return -1;
    8.     }

    9.     g_run_status = new RunStatus;                                                //这个是状态标识

    10.     if (!g_run_status) {
    11.         DF_LOG_ERR("g_run_status allocation failed");
    12.         return -2;
    13.     }

    14.     struct timespec ts = {};

    15.     int ret = absoluteTime(ts);                                                   //获取绝对时间

    16.     if (ret != 0) {
    17.         DF_LOG_ERR("ERROR: absoluteTime returned (%d)", ret);
    18.         return -4;
    19.     }

    20.     ret = HRTWorkQueue::instance().initialize();                                //初始化worker的线程

    21.     if (ret < 0) {
    22.         return ret - 10;
    23.     }

    24.     DF_LOG_DEBUG("Calling DevMgr::initialize");
    25.     ret = DevMgr::initialize();                                                    //加了一个标志位true

    26.     if (ret < 0) {
    27.         return ret - 20;
    28.     }

    29.     DF_LOG_DEBUG("Calling WorkMgr::initialize");
    30.     ret = WorkMgr::initialize();                                                    //这里也加了一个标志位true

    31.     if (ret < 0) {
    32.         return ret - 30;
    33.     }

    34.     return 0;
    35. }

    1. class SyncObj
    2. {
    3. public:
    4.     SyncObj();                                                    //构造函数
    5.     ~SyncObj() = default;

    6.     void lock();                                                //对Mutex上锁
    7.     void unlock();                                              //解锁

    8.     // Returns 0 on success, ETIMEDOUT on timeout                //返回0成功, ETIMEDOUT是超时
    9.     // Use timeout_us = 0 for blocking wait                    //使用timeout_us =0作为阻塞等待
    10.     int waitOnSignal(unsigned long timeout_us);

    11.     void signal();

    12. private:
    13.     pthread_mutex_t m_lock{};                                    //这个大括号是C++11,统一初始化
    14.     pthread_cond_t    m_new_data_cond{};
    15. };

    无欲速,无见小利。欲速,则不达;见小利,则大事不成。
  • 相关阅读:
    Java Jsch SFTP 递归下载文件夹
    spring-jms,spring-boot-starter-activemq JmsTemplate 发送方式
    Spring Boot 入门之消息中间件篇(转发)
    Springboot websocket使用
    FinalCutPro快捷键
    基本CSS布局三
    As Simple as One and Two
    Game of Credit Cards
    WOW Factor
    Lose it!
  • 原文地址:https://www.cnblogs.com/ch122633/p/7363242.html
Copyright © 2020-2023  润新知