123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-04-07 17:19:16
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-04-15 11:26:20
- */
- #ifndef __TASHCENTER_HPP_
- #define __TASHCENTER_HPP_
- #include "ins_base.hpp"
- #include <condition_variable>
- #include <thread>
- #include <queue>
- #include <vector>
- #include <mutex>
- using namespace std;
- namespace ins
- {
- class TaskCenter:public Module
- {
- private:
- TaskCenter();
- public:
- using Ptr = std::shared_ptr<TaskCenter>;
- ~TaskCenter(){this->Destroy();}
- /**
- * @description: 获取实例
- * @param {*}
- * @return {*}
- */
- static std::shared_ptr<TaskCenter> getPtr();
-
- /**
- * @description: 创建实例
- * @param {*}
- * @return {*}
- */
- static std::shared_ptr<TaskCenter> CreateNew();
- /**
- * @description: 初始化
- * @param {*}
- * @return {*}
- */
- int8_t Init() override;
- /**
- * @description: 释放资源
- * @param {*}
- * @return {*}
- */
- void Destroy() override;
- /**
- * @description: 是否正常
- * @param {*}
- * @return {*}
- */
- bool isNormally() override{
- return true;
- }
- /**
- * @description: 任务入队
- * @param {Ptr&} task 任务
- * @return {*}
- */
- int8_t enqueue(ins::InsTask::Ptr& task);
- /**
- * @description: 处理数据包
- * @param {*}
- * @return {*}
- */
- int8_t ProcessingPacket(InsPacket::Ptr& pack);
-
- private:
- queue<ins::InsTask::Ptr> async_Tasks;
- vector<thread> workers;
- condition_variable condition;
- mutex m_mutex;
- bool stop = false;
- };
- } // namespace ins
- #endif
|