Implemented move-constructor of HttpProcessor::Task to use its performance-gain over copy.

This commit is contained in:
Benedikt-Alexander Mokroß 2021-02-23 09:45:46 +01:00
parent 8badb89a1c
commit ca19e5b072
3 changed files with 17 additions and 2 deletions

View File

@ -74,7 +74,7 @@ void HttpConnectionHandler::handleConnection(const std::shared_ptr<oatpp::data::
connection->setInputStreamIOMode(oatpp::data::stream::IOMode::BLOCKING);
/* Create working thread */
std::thread thread(&HttpProcessor::Task::run, HttpProcessor::Task(m_components, connection, &m_spawns));
std::thread thread(&HttpProcessor::Task::run, std::move(HttpProcessor::Task(m_components, connection, &m_spawns)));
/* Get hardware concurrency -1 in order to have 1cpu free of workers. */
v_int32 concurrency = oatpp::concurrency::getHardwareConcurrency();

View File

@ -236,6 +236,14 @@ HttpProcessor::Task::Task(const HttpProcessor::Task &copy)
(*m_counter)++;
}
HttpProcessor::Task::Task(HttpProcessor::Task &&move)
: m_components(std::move(move.m_components))
, m_connection(std::move(move.m_connection))
, m_counter(move.m_counter)
{
move.m_counter = nullptr;
}
void HttpProcessor::Task::run(){
m_connection->initContexts();
@ -258,7 +266,9 @@ void HttpProcessor::Task::run(){
}
HttpProcessor::Task::~Task() {
(*m_counter)--;
if (m_counter != nullptr) {
(*m_counter)--;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -207,6 +207,11 @@ public:
*/
Task(const Task &copy);
/**
* Move-Constructor to correclty count tasks;
*/
Task(Task &&move);
/**
* Destructor, needed for counting.
*/