Commit dd5b951a by “liusq”

取消等待线程池执行完

parent 9a1411ee
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <vector> #include <vector>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <mutex> #include <mutex>
#include <condition_variable>
class AlgorithmTaskManage{ class AlgorithmTaskManage{
public: public:
AlgorithmTaskManage(); AlgorithmTaskManage();
...@@ -90,6 +91,7 @@ private: ...@@ -90,6 +91,7 @@ private:
selected->setIsRunning(true); // 立刻标记为正在运行 selected->setIsRunning(true); // 立刻标记为正在运行
return selected; return selected;
} }
template<typename T> template<typename T>
void resetSemaphoreAndClearObjects(Common& instance, QSemaphore*& semaphore, std::vector<T*>& containers, int len) { void resetSemaphoreAndClearObjects(Common& instance, QSemaphore*& semaphore, std::vector<T*>& containers, int len) {
if (semaphore != nullptr) { if (semaphore != nullptr) {
...@@ -107,6 +109,7 @@ private: ...@@ -107,6 +109,7 @@ private:
instance.deleteObj(semaphore); instance.deleteObj(semaphore);
} }
} }
static AlgorithmTaskManage* instance; static AlgorithmTaskManage* instance;
std::vector<HumanDetection*>humanDetections; std::vector<HumanDetection*>humanDetections;
......
...@@ -23,18 +23,23 @@ CameraHandle::CameraHandle(QString &url, QString &httpUrl, QString &sSn, int &ch ...@@ -23,18 +23,23 @@ CameraHandle::CameraHandle(QString &url, QString &httpUrl, QString &sSn, int &ch
devConfig(devConfig) devConfig(devConfig)
{ {
connect(this, SIGNAL(afterDownloadFile(int,int,QString)), this, SLOT(pushRecordToCloud(int,int,QString)),Qt::QueuedConnection); connect(this, SIGNAL(afterDownloadFile(int,int,QString)), this, SLOT(pushRecordToCloud(int,int,QString)),Qt::QueuedConnection);
faceMapWorker.setX(0); faceMapWorker.setX(0);
faceMapWorker.setY(0); faceMapWorker.setY(0);
} }
CameraHandle::~CameraHandle() { CameraHandle::~CameraHandle() {
stopRequested_=true;
semaphore.acquire();
Common & instace= Common::getInstance(); Common & instace= Common::getInstance();
dev_snap_syn_timer->stop(); dev_snap_syn_timer->stop();
QThreadPool::globalInstance()->waitForDone();
ScopeSemaphoreExit guard([this]() {
semaphore.release(); // 释放信号量
});
instace.deleteObj(dev_snap_syn_timer); instace.deleteObj(dev_snap_syn_timer);
instace.deleteObj(loginParam); instace.deleteObj(loginParam);
instace.deleteObj(sxMediaFaceImageReq); instace.deleteObj(sxMediaFaceImageReq);
...@@ -362,7 +367,6 @@ void CameraHandle::sdkDownloadFileByTime(XSDK_HANDLE hDevice,int id, ...@@ -362,7 +367,6 @@ void CameraHandle::sdkDownloadFileByTime(XSDK_HANDLE hDevice,int id,
} }
int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) { int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) {
if (stopRequested_) return -1;
if (!semaphore.tryAcquire()) { if (!semaphore.tryAcquire()) {
qInfo() <<sSn<<"sdkDevSnapSyn:正在执行线程"; qInfo() <<sSn<<"sdkDevSnapSyn:正在执行线程";
...@@ -408,7 +412,7 @@ int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) { ...@@ -408,7 +412,7 @@ int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) {
} }
void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
if (stopRequested_) return;
if(hDevice<=0){ if(hDevice<=0){
qInfo() << "相机断线"; qInfo() << "相机断线";
return; return;
......
...@@ -25,20 +25,22 @@ ...@@ -25,20 +25,22 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <QString> #include <QString>
#include <QObject>
#include <QTimer> #include <QTimer>
#include <QThreadPool> #include <QThreadPool>
#include <QQueue> #include <QQueue>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <QSemaphore> #include <QSemaphore>
#include <atomic> #include <atomic>
enum CAR_INFORMATION { enum CAR_INFORMATION {
Exit, //出场 Exit, //出场
Mobilization, //进场 Mobilization, //进场
ExitAndMobilization // ExitAndMobilization //
}; };
class CameraHandle: public QObject { class CameraHandle: public QObject
{
Q_OBJECT Q_OBJECT
public: public:
CameraHandle(QString &url,QString &httpUrl,QString &sSn, int &channel, int imageSave, CameraHandle(QString &url,QString &httpUrl,QString &sSn, int &channel, int imageSave,
float &heightReference,vides_data::responseConfig &devConfig); float &heightReference,vides_data::responseConfig &devConfig);
...@@ -145,6 +147,7 @@ public: ...@@ -145,6 +147,7 @@ public:
int findPointRegion(ParkingSpaceInfo &prakArea); int findPointRegion(ParkingSpaceInfo &prakArea);
int determineArea(ParkingSpaceInfo &prakArea); int determineArea(ParkingSpaceInfo &prakArea);
signals: signals:
void callbackFrameReady(const cv::Mat &frame, const QString &url); void callbackFrameReady(const cv::Mat &frame, const QString &url);
...@@ -159,8 +162,7 @@ private : ...@@ -159,8 +162,7 @@ private :
int hDevice; int hDevice;
int channel; int channel;
QString httpUrl; QString httpUrl;
bool stopRequested_ = false;
SXSDKLoginParam *loginParam; SXSDKLoginParam *loginParam;
SXMediaFaceImageReq *sxMediaFaceImageReq; SXMediaFaceImageReq *sxMediaFaceImageReq;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment