You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
1.9 KiB
97 lines
1.9 KiB
/*
|
|
* @Author: your name
|
|
* @Date: 2022-04-20 15:49:50
|
|
* @LastEditTime: 2025-09-16 10:14:05
|
|
* @LastEditors: xiewenji 527774126@qq.com
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
|
*/
|
|
#ifndef Task_H_
|
|
#define Task_H_
|
|
|
|
#include <string>
|
|
#include <opencv2/opencv.hpp>
|
|
#include <thread>
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
#include <queue>
|
|
#include <vector>
|
|
#include <atomic>
|
|
#include <memory>
|
|
|
|
enum TaskName
|
|
{
|
|
Task_AI,
|
|
Task_AI_Other,
|
|
Task_Class,
|
|
Task_Count,
|
|
};
|
|
enum TaskStep
|
|
{
|
|
TaskStep_Idle,
|
|
TaskStep_Waite,
|
|
TaskStep_run,
|
|
TaskStep_compate,
|
|
};
|
|
struct TaskInfo
|
|
{
|
|
TaskName taskname;
|
|
TaskStep status; // 运行状态
|
|
int nresult; // 运行结果
|
|
|
|
// 🔑 新增变量
|
|
std::mutex mtx;
|
|
std::condition_variable cv;
|
|
|
|
// 设置状态,线程安全
|
|
void SetStatus(TaskStep newStatus)
|
|
{
|
|
{
|
|
std::lock_guard<std::mutex> lock(mtx);
|
|
status = newStatus;
|
|
}
|
|
cv.notify_all(); // 通知等待者
|
|
}
|
|
bool isComplate()
|
|
{
|
|
bool bcom = false;
|
|
{
|
|
std::lock_guard<std::mutex> lock(mtx);
|
|
if (status == TaskStep_compate)
|
|
{
|
|
bcom = true;
|
|
}
|
|
}
|
|
|
|
return bcom;
|
|
}
|
|
// 等待任务完成
|
|
void waitComplate()
|
|
{
|
|
std::unique_lock<std::mutex> lock(mtx);
|
|
cv.wait(lock, [this]
|
|
{ return status == TaskStep_compate; });
|
|
}
|
|
};
|
|
using namespace std;
|
|
|
|
class Task
|
|
{
|
|
public:
|
|
Task();
|
|
~Task();
|
|
int sendTask(std::shared_ptr<TaskInfo> task);
|
|
std::shared_ptr<TaskInfo> GetTask();
|
|
|
|
private:
|
|
std::queue<std::shared_ptr<TaskInfo>> m_tasks_;
|
|
std::mutex m_task_mutex_;
|
|
std::condition_variable m_task_cv_;
|
|
|
|
private:
|
|
public:
|
|
private:
|
|
private:
|
|
};
|
|
|
|
#endif |