From 58d904a328c0d849769b483e901a0be9426b8209 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 20 七月 2021 20:20:44 +0800 Subject: [PATCH] 调整Request C.BHFree的位置 --- box/io_service.cpp | 33 ++++++++------------------------- 1 files changed, 8 insertions(+), 25 deletions(-) diff --git a/box/io_service.cpp b/box/io_service.cpp index 1d531e0..5640d50 100644 --- a/box/io_service.cpp +++ b/box/io_service.cpp @@ -16,33 +16,16 @@ * ===================================================================================== */ #include "io_service.h" -#include <chrono> -using namespace std::chrono_literals; -bool IoService::Start() +IoService::IoService() : + guard_(io_.get_executor()) { - Stop(); - bool cur = false; - if (!run_.compare_exchange_strong(cur, true)) { - return false; - } - - auto proc = [this]() { - while (run_) { - io_.run_one_for(100ms); - } - OnStop(); - }; - std::thread(proc).swap(worker_); - return true; + std::thread([this]() { io_.run(); }).swap(worker_); } - -void IoService::Stop() +IoService::~IoService() { - bool cur = true; - if (run_.compare_exchange_strong(cur, false)) { - if (worker_.joinable()) { - worker_.join(); - } - } + guard_.reset(); + io_.stop(); // normally not needed, but make sure run() exits. + if (worker_.joinable()) + worker_.join(); } -- Gitblit v1.8.0