Skip to content

Commit

Permalink
[Refactor] CpuBoundWork#CpuBoundWork(): require an io_context::strand
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Sep 27, 2024
1 parent 6d5b447 commit b413287
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/base/io-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion lib/base/io-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions lib/remote/httpserverconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,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;
Expand Down Expand Up @@ -428,13 +429,14 @@ bool ProcessRequest(
boost::beast::http::response<boost::beast::http::string_body>& response,
HttpServerConnection& server,
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);

HttpHandler::ProcessRequest(stream, authenticatedUser, request, response, yc, server, handlingRequest);
} catch (const std::exception& ex) {
Expand Down Expand Up @@ -542,13 +544,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_HasStartedStreaming, yc)) {
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HasStartedStreaming, yc, m_IoStrand)) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/remote/jsonrpcconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b413287

Please sign in to comment.