BaseCalculateThread.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "BaseCalculateThread.h"
  2. BaseCalculateThread::BaseCalculateThread(CalculateThreadInfo_t& threadInfo)
  3. : m_threadInfo(threadInfo)
  4. {
  5. m_logger = spdlog::get("ACAServer");
  6. if (m_logger == nullptr)
  7. {
  8. fmt::print("没有名为“ACAServer”的记录器\n");
  9. return;
  10. }
  11. }
  12. /**
  13. * @brief 线程任务函数,创建线程时会调用此函数
  14. */
  15. void BaseCalculateThread::threadTask()
  16. {
  17. m_logBase = fmt::format("对比项: {} 线程类型: {}",
  18. m_threadInfo.compareItemInfo.strName.toStdString(),
  19. static_cast<int>(m_threadInfo.threadType));
  20. m_threadInfo.threadState = EThreadState::State_Running;
  21. m_isStop = false;
  22. task();
  23. SPDLOG_LOGGER_INFO(m_logger, "{} 执行结束", m_logBase);
  24. m_isRunning = false;
  25. /* 清理资源 */
  26. /* 设置全局的线程状态 */
  27. m_threadInfo.threadState = EThreadState::State_Stopped;
  28. m_isStop.store(true);
  29. }
  30. /* 停止线程 */
  31. void BaseCalculateThread::stopThread()
  32. {
  33. m_isRunning = false;
  34. while(m_isStop.load() == false)
  35. {
  36. /* 100us检查一次 */
  37. std::this_thread::sleep_for(std::chrono::microseconds(100));
  38. }
  39. }