From 96c71f29d34eb7a4af8e9f0eafcee8f80da3fb6a Mon Sep 17 00:00:00 2001 From: lzq <2495532633@qq.com> Date: Tue, 6 Jan 2026 13:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=8D=A0=E7=94=A8=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/barrier/generic_barrier.cpp | 22 ++++++++++++++++++++++ src/barrier/generic_barrier.h | 3 ++- src/recognize_processor.cpp | 30 ------------------------------ src/recognize_processor.h | 2 -- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/barrier/generic_barrier.cpp b/src/barrier/generic_barrier.cpp index 49c500f..1351b73 100644 --- a/src/barrier/generic_barrier.cpp +++ b/src/barrier/generic_barrier.cpp @@ -53,7 +53,29 @@ namespace zsy std::jthread t([recognizeResult,name,sn] { LOGGER_INFO("正在处理车牌识别结果:{}、{}、{}", recognizeResult->license, name, sn); + { + std::lock_guard lock(tasks_mutex); + if (tasks.contains(sn)) + { + if (auto oldLicense = tasks.at(sn); oldLicense == recognizeResult->license) + { + LOGGER_INFO("重复识别:{}、{}", sn, oldLicense); + } else + { + Application::deviceHolder->getSoundColumn(sn)->play("请等待前车业务完成后重新识别"); + LOGGER_INFO("当前道闸正在处理:{}、{}", sn, oldLicense); + } + return; + } else + { + tasks[sn] = recognizeResult->license; + } + } RecognizeProcessor::process(recognizeResult); + { + std::lock_guard lock(tasks_mutex); + tasks.erase(sn); + } LOGGER_INFO("车牌识别结果处理完成"); }); t.detach(); diff --git a/src/barrier/generic_barrier.h b/src/barrier/generic_barrier.h index be9e26e..5415278 100644 --- a/src/barrier/generic_barrier.h +++ b/src/barrier/generic_barrier.h @@ -144,7 +144,8 @@ namespace zsy class GenericBarrier : public Barrier { BarrierProperties config; - + inline static std::unordered_map tasks; + inline static std::mutex tasks_mutex; public: explicit GenericBarrier(const BarrierProperties &config); diff --git a/src/recognize_processor.cpp b/src/recognize_processor.cpp index 9b4c582..18a85ce 100644 --- a/src/recognize_processor.cpp +++ b/src/recognize_processor.cpp @@ -11,24 +11,6 @@ namespace zsy { const std::string &sn = data->sn; const std::string &license = data->license; - { - std::lock_guard lock(tasks_mutex); - if (tasks.contains(sn)) - { - if (auto oldLicense = tasks.at(sn); oldLicense == license) - { - LOGGER_INFO("重复识别:{}、{}", sn, oldLicense); - } else - { - Application::deviceHolder->getSoundColumn(sn)->play("请等待前车业务完成后重新识别"); - LOGGER_INFO("当前道闸正在处理:{}、{}", sn, oldLicense); - } - return; - } else - { - tasks[sn] = license; - } - } try { std::jthread t; @@ -49,23 +31,11 @@ namespace zsy return; } addition_process(reportPassResult.data.orderNo, data); - { - std::lock_guard lock(tasks_mutex); - tasks.erase(sn); - } } catch (std::exception &e) { - { - std::lock_guard lock(tasks_mutex); - tasks.erase(sn); - } LOGGER_ERROR("车牌识别结果处理失败: {}", e.what()); } catch (...) { - { - std::lock_guard lock(tasks_mutex); - tasks.erase(sn); - } LOGGER_ERROR("未知异常,车牌识别结果处理失败"); } } diff --git a/src/recognize_processor.h b/src/recognize_processor.h index 6ab0077..f322fc6 100644 --- a/src/recognize_processor.h +++ b/src/recognize_processor.h @@ -13,8 +13,6 @@ namespace zsy class RecognizeProcessor { public: - inline static std::unordered_map tasks; - inline static std::mutex tasks_mutex; static void process(std::shared_ptr data);