mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 08:04:14 +02:00
[Refactor] CpuBoundWork#CpuBoundWork(): require an io_context::strand
This commit is contained in:
parent
9018385c1a
commit
659bb9e03a
@ -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());
|
||||
|
@ -20,6 +20,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>
|
||||
|
||||
#if BOOST_VERSION >= 108700
|
||||
@ -37,7 +38,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;
|
||||
|
@ -424,7 +424,8 @@ bool ProcessRequest(
|
||||
bool& hasStartedStreaming,
|
||||
const WaitGroup::Ptr& waitGroup,
|
||||
std::chrono::steady_clock::duration& cpuBoundWorkTime,
|
||||
boost::asio::yield_context& yc
|
||||
boost::asio::yield_context& yc,
|
||||
boost::asio::io_context::strand& strand
|
||||
)
|
||||
{
|
||||
namespace http = boost::beast::http;
|
||||
@ -432,7 +433,7 @@ bool ProcessRequest(
|
||||
try {
|
||||
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
||||
auto start (std::chrono::steady_clock::now());
|
||||
CpuBoundWork handlingRequest (yc);
|
||||
CpuBoundWork handlingRequest (yc, strand);
|
||||
cpuBoundWorkTime = std::chrono::steady_clock::now() - start;
|
||||
|
||||
Defer resetHandlingRequest ([&m_HandlingRequest] { m_HandlingRequest = nullptr; });
|
||||
@ -555,7 +556,7 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
|
||||
|
||||
m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
|
||||
|
||||
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, m_WaitGroup, cpuBoundWorkTime, yc)) {
|
||||
if (!ProcessRequest(*m_Stream, request, authenticatedUser, response, *this, m_HandlingRequest, m_HasStartedStreaming, m_WaitGroup, cpuBoundWorkTime, yc, m_IoStrand)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
|
||||
auto start (ch::steady_clock::now());
|
||||
|
||||
try {
|
||||
CpuBoundWork handleMessage (yc);
|
||||
CpuBoundWork handleMessage (yc, m_IoStrand);
|
||||
|
||||
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
||||
cpuBoundDuration = ch::steady_clock::now() - start;
|
||||
|
Loading…
x
Reference in New Issue
Block a user