后端算法池更新新逻辑,未完善
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <threadPoolManager.h>
|
||||
#include <FrontendBackendBridge.h>
|
||||
#include <algorithmThread.h>
|
||||
#include <algo/algorithmThread.h>
|
||||
#include <algo/pinAioEvalute.h>
|
||||
/// <summary>
|
||||
/// 检查目标文件夹是否存在,不存在则创建
|
||||
/// </summary>
|
||||
@@ -42,86 +43,66 @@ threadManager::threadManager(QObject* parent) : QThread(parent)
|
||||
//辅助线程初始化
|
||||
//oriSaveThread->oriThread = true;
|
||||
//oriSaveThread->Init(this);
|
||||
this->start();
|
||||
}
|
||||
|
||||
//resSaveThread->Init(this);
|
||||
threadAmount = bridge.back.json.algoThreads.algoDataMap.size();
|
||||
for (int i = 0; i < threadAmount; i++)
|
||||
void threadManager::process()
|
||||
{
|
||||
#pragma region 检查队列是否有新的数据
|
||||
queueMutex.lock();
|
||||
while (insertQueue.size() > 0)
|
||||
processData.push_back(std::make_pair(progress::waitImg,insertQueue.dequeue()));
|
||||
queueMutex.unlock();
|
||||
#pragma endregion
|
||||
#pragma region 检测状态并处理
|
||||
for (auto& data : processData)
|
||||
{
|
||||
algoThread* aT = new algoThread();
|
||||
aT->Init(this);
|
||||
//QObject::connect(aT, &algoThread::subThreadStart, [&]() {
|
||||
// supportThread->start();
|
||||
// });
|
||||
algoThreadList.push_back(aT);
|
||||
std::shared_ptr <detData> detDataPtr = data.second;
|
||||
switch (data.first)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
||||
|
||||
void threadManager::run()
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
process();
|
||||
QThread::msleep(1);
|
||||
}
|
||||
}
|
||||
void threadManager::addTask(std::shared_ptr <detData> data)
|
||||
{
|
||||
//cout << __LINE__ << "insert Data " << data ->timeCode<< endl;
|
||||
{
|
||||
algoThreadCls::datastruct _struct = bridge.back.json.algoThreads.getData(data->algoThreadName);
|
||||
data->algoThreadIndex = _struct.threadIndex;
|
||||
data->resShowIndex = _struct.showIndex;
|
||||
data->imgAmountMin = _struct.imgAmountMin;
|
||||
}
|
||||
{
|
||||
CameraListCls::datastruct _struct = bridge.back.json.camera.getData(data->cameraKeyName);
|
||||
data->oriShowIndex = _struct.showIndex;
|
||||
}
|
||||
//{
|
||||
// CameraListCls::datastruct _struct = bridge.back.json.camera.getData(data->cameraKeyName);
|
||||
// data->oriShowIndex = _struct.showIndex;
|
||||
//}
|
||||
insertQueueMutex.lock();
|
||||
//insertQueue.push_back(data);
|
||||
int threadId = data->algoThreadIndex;
|
||||
if (threadId == -1)
|
||||
{
|
||||
cout << "threadId return -1 ,algoName " << data->algoThreadName.toStdString() << endl;
|
||||
return;
|
||||
}
|
||||
algoThreadList[threadId]->addDetTask(data);
|
||||
insertQueue.enqueue(data);
|
||||
insertQueueMutex.unlock();
|
||||
//this->start();
|
||||
}
|
||||
bool threadManager::addTaskFreeThread(std::shared_ptr <detData> data)
|
||||
{
|
||||
#if 0
|
||||
int index = 0;
|
||||
for (index = 0; index < threadPoolList.size(); index++)
|
||||
{
|
||||
if (threadPoolList[index]->isRunning() == false)
|
||||
{
|
||||
threadPoolList[index]->addDetTask(data);
|
||||
threadPoolList[index]->start();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (index = 0; index < threadPoolList.size(); index++)
|
||||
{
|
||||
if (threadPoolList[index]->nextObj.isEmpty() == true)
|
||||
{
|
||||
threadPoolList[index]->addDetTask(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
|
||||
}
|
||||
threadManager::~threadManager()
|
||||
{
|
||||
for (auto thread : algoThreadList)
|
||||
{
|
||||
thread->m_runFlag = false;
|
||||
thread->terminate();
|
||||
while (thread->isRunning() == true);
|
||||
}
|
||||
for (auto thread : algoThreadList)
|
||||
{
|
||||
delete thread;
|
||||
}
|
||||
}
|
||||
////////////////DET//DATA//////////////////
|
||||
sncodeCls::sncodeCls()
|
||||
|
||||
Reference in New Issue
Block a user