mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-23 01:38:11 +02:00
[Refactor] CpuBoundWork#CpuBoundWork(): require an io_context::strand
This commit is contained in:
parent
da79b0dfe8
commit
5324f1c234
@ -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;
|
||||
|
@ -413,13 +413,14 @@ void ProcessRequest(
|
||||
HttpResponse& response,
|
||||
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
|
||||
)
|
||||
{
|
||||
try {
|
||||
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
|
||||
auto start (std::chrono::steady_clock::now());
|
||||
auto handlingRequest (std::make_shared<CpuBoundWork>(yc));
|
||||
auto handlingRequest (std::make_shared<CpuBoundWork>(yc, strand));
|
||||
cpuBoundWorkTime = std::chrono::steady_clock::now() - start;
|
||||
|
||||
response.SetCpuBoundWork(handlingRequest);
|
||||
@ -522,7 +523,7 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
|
||||
|
||||
m_Seen = std::numeric_limits<decltype(m_Seen)>::max();
|
||||
|
||||
ProcessRequest(request, response, m_WaitGroup, cpuBoundWorkTime, yc);
|
||||
ProcessRequest(request, response, m_WaitGroup, cpuBoundWorkTime, yc, m_IoStrand);
|
||||
|
||||
if (!request.keep_alive() || !m_ConnectionReusable) {
|
||||
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