- int Framework::initialize()
- {
- DF_LOG_DEBUG("Framework::initialize");
-
- g_framework = new SyncObj; //这个应该是各同步类
-
- if (!g_framework) {
- DF_LOG_ERR("ERROR: falled to allocate g_framework");
- return -1;
- }
-
- g_run_status = new RunStatus; //这个是状态标识
-
- if (!g_run_status) {
- DF_LOG_ERR("g_run_status allocation failed");
- return -2;
- }
-
- struct timespec ts = {};
-
- int ret = absoluteTime(ts); //获取绝对时间
-
- if (ret != 0) {
- DF_LOG_ERR("ERROR: absoluteTime returned (%d)", ret);
- return -4;
- }
-
- ret = HRTWorkQueue::instance().initialize(); //初始化worker的线程
-
- if (ret < 0) {
- return ret - 10;
- }
-
- DF_LOG_DEBUG("Calling DevMgr::initialize");
- ret = DevMgr::initialize(); //加了一个标志位true
-
- if (ret < 0) {
- return ret - 20;
- }
-
- DF_LOG_DEBUG("Calling WorkMgr::initialize");
- ret = WorkMgr::initialize(); //这里也加了一个标志位true
-
- if (ret < 0) {
- return ret - 30;
- }
-
- return 0;
- }
- class SyncObj
- {
- public:
- SyncObj(); //构造函数
- ~SyncObj() = default;
-
- void lock(); //对Mutex上锁
- void unlock(); //解锁
-
- // Returns 0 on success, ETIMEDOUT on timeout //返回0成功, ETIMEDOUT是超时
- // Use timeout_us = 0 for blocking wait //使用timeout_us =0作为阻塞等待
- int waitOnSignal(unsigned long timeout_us);
-
- void signal();
-
- private:
- pthread_mutex_t m_lock{}; //这个大括号是C++11,统一初始化
- pthread_cond_t m_new_data_cond{};
- };
给主人留下些什么吧!~~
评论热议