#include "BaseCalculateThread.h" BaseCalculateThread::BaseCalculateThread(CalculateThreadInfo_t& threadInfo) : m_threadInfo(threadInfo) { m_logger = spdlog::get("ACAServer"); if (m_logger == nullptr) { fmt::print("没有名为“ACAServer”的记录器\n"); return; } } /** * @brief 线程任务函数,创建线程时会调用此函数 */ void BaseCalculateThread::threadTask() { m_logBase = fmt::format("对比项: {} 线程类型: {}", m_threadInfo.compareItemInfo.strName.toStdString(), static_cast(m_threadInfo.threadType)); m_threadInfo.threadState = EThreadState::State_Running; m_isStop = false; task(); SPDLOG_LOGGER_INFO(m_logger, "{} 执行结束", m_logBase); m_isRunning = false; /* 清理资源 */ /* 设置全局的线程状态 */ m_threadInfo.threadState = EThreadState::State_Stopped; m_isStop.store(true); } /* 停止线程 */ void BaseCalculateThread::stopThread() { m_isRunning = false; while(m_isStop.load() == false) { /* 100us检查一次 */ std::this_thread::sleep_for(std::chrono::microseconds(100)); } }