完善部分算法线程
This commit is contained in:
@@ -48,43 +48,51 @@ threadManager::threadManager(QObject* parent) : QThread(parent)
|
||||
|
||||
void threadManager::process()
|
||||
{
|
||||
|
||||
#pragma region 检查队列是否有新的数据
|
||||
queueMutex.lock();
|
||||
while (insertQueue.size() > 0)
|
||||
processData.push_back(std::make_pair(progress::waitImg,insertQueue.dequeue()));
|
||||
waitImgData.push_back(insertQueue.dequeue());
|
||||
queueMutex.unlock();
|
||||
#pragma endregion
|
||||
#pragma region 检测状态并处理
|
||||
for (auto& data : processData)
|
||||
#pragma region 等待图片满足要求后异步执行算法函数
|
||||
for (auto it = waitImgData.begin(); it != waitImgData.end();)
|
||||
{
|
||||
std::shared_ptr <detData> detDataPtr = data.second;
|
||||
switch (data.first)
|
||||
std::shared_ptr<detData> ptr = *it;
|
||||
if (ptr->imgs.size() >= ptr->imgAmountMin)
|
||||
{
|
||||
case waitImg:
|
||||
if (detDataPtr->imgs.size() >= detDataPtr->imgAmountMin)
|
||||
{
|
||||
futures.insert(std::make_pair(detDataPtr->timeCode,std::async(std::launch::async, pinAioEvalute, detDataPtr)));
|
||||
data.first = processing;
|
||||
}
|
||||
break;
|
||||
case processing:
|
||||
auto futrue = futures.find(detDataPtr->timeCode);
|
||||
if (futrue == futures.end())
|
||||
{
|
||||
std::cout << "???????" << std::endl;
|
||||
}
|
||||
if (futrue->second.valid())
|
||||
{
|
||||
//processData
|
||||
}
|
||||
futures.insert(std::make_pair(ptr->timeCode, std::async(std::launch::async, pinAioEvalute, ptr)));
|
||||
it = waitImgData.erase(it);
|
||||
processData.push_back(ptr);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
#pragma endregion
|
||||
#pragma region 执行完毕后异步获取储存使用结果
|
||||
for (auto it = processData.begin(); it != processData.end();)
|
||||
{
|
||||
std::shared_ptr<detData> ptr = *it;
|
||||
futrueIte = futures.find(ptr->timeCode);
|
||||
if (futrueIte->second.valid())
|
||||
{
|
||||
it = processData.erase(it); // 删除元素后,更新迭代器
|
||||
futures.erase(futrueIte);
|
||||
std::async(std::launch::async, &threadManager::resultHandle, this, ptr);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
||||
|
||||
}
|
||||
void threadManager::resultHandle(std::shared_ptr <detData>)
|
||||
{
|
||||
|
||||
}
|
||||
void threadManager::run()
|
||||
{
|
||||
while(1)
|
||||
while (runFlag == true)
|
||||
{
|
||||
process();
|
||||
QThread::msleep(1);
|
||||
@@ -103,6 +111,11 @@ void threadManager::addTask(std::shared_ptr <detData> data)
|
||||
}
|
||||
threadManager::~threadManager()
|
||||
{
|
||||
runFlag = false;
|
||||
this->stop();
|
||||
this->terminate();
|
||||
processData.clear();
|
||||
futures.clear();
|
||||
}
|
||||
////////////////DET//DATA//////////////////
|
||||
sncodeCls::sncodeCls()
|
||||
|
||||
Reference in New Issue
Block a user