[Refactor] CpuBoundWork#CpuBoundWork(): require an io_context::strand

This commit is contained in:
Alexander A. Klimov 2024-02-20 12:41:41 +01:00
parent 52d53ec1ba
commit 5ca0d7102a
4 changed files with 11 additions and 8 deletions

View File

@ -16,7 +16,7 @@
using namespace icinga;
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, boost::asio::io_context::strand&)
: m_Done(false)
{
auto& ioEngine (IoEngine::Get());

View File

@ -17,6 +17,7 @@
#include <boost/exception/all.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_context_strand.hpp>
#include <boost/asio/spawn.hpp>
namespace icinga
@ -30,7 +31,7 @@ namespace icinga
class CpuBoundWork
{
public:
CpuBoundWork(boost::asio::yield_context yc);
CpuBoundWork(boost::asio::yield_context yc, boost::asio::io_context::strand&);
CpuBoundWork(const CpuBoundWork&) = delete;
CpuBoundWork(CpuBoundWork&&) = delete;
CpuBoundWork& operator=(const CpuBoundWork&) = delete;

View File

@ -345,7 +345,8 @@ bool EnsureValidBody(
ApiUser::Ptr& authenticatedUser,
boost::beast::http::response<boost::beast::http::string_body>& response,
bool& shuttingDown,
boost::asio::yield_context& yc
boost::asio::yield_context& yc,
boost::asio::io_context::strand& strand
)
{
namespace http = boost::beast::http;
@ -436,13 +437,14 @@ bool ProcessRequest(
HttpServerConnection& server,
CpuBoundWork*& m_HandlingRequest,
bool& hasStartedStreaming,
boost::asio::yield_context& yc
boost::asio::yield_context& yc,
boost::asio::io_context::strand& strand
)
{
namespace http = boost::beast::http;
try {
CpuBoundWork handlingRequest (yc);
CpuBoundWork handlingRequest (yc, strand);
Defer resetHandlingRequest ([&m_HandlingRequest] { m_HandlingRequest = nullptr; });
m_HandlingRequest = &handlingRequest;
@ -552,13 +554,13 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
break;
}
if (!EnsureValidBody(*m_Stream, buf, parser, authenticatedUser, response, m_ShuttingDown, yc)) {
if (!EnsureValidBody(*m_Stream, buf, parser, authenticatedUser, response, m_ShuttingDown, yc, m_IoStrand)) {
break;
}
m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, yc)) {
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, yc, m_IoStrand)) {
break;
}

View File

@ -78,7 +78,7 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
m_Seen = Utility::GetTime();
try {
CpuBoundWork handleMessage (yc);
CpuBoundWork handleMessage (yc, m_IoStrand);
MessageHandler(message);