Have concurrency represent the actual number threads used

This commit is contained in:
The-EDev 2021-12-20 11:04:55 +03:00
parent f4785cda68
commit 77758e6241
No known key found for this signature in database
GPG Key ID: 51C45DC0C413DCD9
2 changed files with 5 additions and 5 deletions

View File

@ -156,8 +156,9 @@ namespace crow
/// Run the server on multiple threads using a specific number
self_t& concurrency(std::uint16_t concurrency)
{
if (concurrency < 1)
concurrency = 1;
if (concurrency < 2) // using 2 instead of 1 because 1 will be subtracted later.
concurrency = 2;
concurrency--; // Account for the main (acceptor) thread creating all the other threads.
concurrency_ = concurrency;
return *this;
}

View File

@ -31,7 +31,7 @@ namespace crow
signals_(io_service_),
tick_timer_(io_service_),
handler_(handler),
concurrency_(concurrency == 0 ? 1 : concurrency),
concurrency_(concurrency),
timeout_(timeout),
server_name_(server_name),
port_(port),
@ -137,8 +137,7 @@ namespace crow
handler_->port(port_);
CROW_LOG_INFO << server_name_ << " server is running at " << (handler_->ssl_used() ? "https://" : "http://") << bindaddr_ << ":" << acceptor_.local_endpoint().port()
<< " using " << concurrency_ << " threads";
CROW_LOG_INFO << server_name_ << " server is running at " << (handler_->ssl_used() ? "https://" : "http://") << bindaddr_ << ":" << acceptor_.local_endpoint().port() << " using " << (concurrency_ + 1) << " threads"; // +1 is for the main thread
CROW_LOG_INFO << "Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.";
signals_.async_wait(