Skip to content

Commit daadf8a

Browse files
committed
[Refactor] CpuBoundWork#CpuBoundWork(): require an io_context::strand
1 parent 19015c2 commit daadf8a

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

lib/base/io-engine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
using namespace icinga;
1818

19-
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc)
19+
CpuBoundWork::CpuBoundWork(boost::asio::yield_context yc, boost::asio::io_context::strand&)
2020
: m_Done(false)
2121
{
2222
auto& ioEngine (IoEngine::Get());

lib/base/io-engine.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <boost/exception/all.hpp>
2121
#include <boost/asio/deadline_timer.hpp>
2222
#include <boost/asio/io_context.hpp>
23+
#include <boost/asio/io_context_strand.hpp>
2324
#include <boost/asio/spawn.hpp>
2425

2526
#if BOOST_VERSION >= 108700
@@ -37,7 +38,7 @@ namespace icinga
3738
class CpuBoundWork
3839
{
3940
public:
40-
CpuBoundWork(boost::asio::yield_context yc);
41+
CpuBoundWork(boost::asio::yield_context yc, boost::asio::io_context::strand&);
4142
CpuBoundWork(const CpuBoundWork&) = delete;
4243
CpuBoundWork(CpuBoundWork&&) = delete;
4344
CpuBoundWork& operator=(const CpuBoundWork&) = delete;

lib/remote/httpserverconnection.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,16 @@ bool ProcessRequest(
423423
CpuBoundWork*& m_HandlingRequest,
424424
bool& hasStartedStreaming,
425425
std::chrono::steady_clock::duration& cpuBoundWorkTime,
426-
boost::asio::yield_context& yc
426+
boost::asio::yield_context& yc,
427+
boost::asio::io_context::strand& strand
427428
)
428429
{
429430
namespace http = boost::beast::http;
430431

431432
try {
432433
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
433434
auto start (std::chrono::steady_clock::now());
434-
CpuBoundWork handlingRequest (yc);
435+
CpuBoundWork handlingRequest (yc, strand);
435436
cpuBoundWorkTime = std::chrono::steady_clock::now() - start;
436437

437438
Defer resetHandlingRequest ([&m_HandlingRequest] { m_HandlingRequest = nullptr; });
@@ -554,7 +555,7 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
554555

555556
m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
556557

557-
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, cpuBoundWorkTime, yc)) {
558+
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, cpuBoundWorkTime, yc, m_IoStrand)) {
558559
break;
559560
}
560561

lib/remote/jsonrpcconnection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
9191
auto start (ch::steady_clock::now());
9292

9393
try {
94-
CpuBoundWork handleMessage (yc);
94+
CpuBoundWork handleMessage (yc, m_IoStrand);
9595

9696
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
9797
cpuBoundDuration = ch::steady_clock::now() - start;

0 commit comments

Comments
 (0)