Make ParallelSocketReactor thread namable (#3642)

make ParallelSocketReactor thread namable
This commit is contained in:
JackyWoo 2022-06-24 18:37:56 +08:00 committed by GitHub
parent ae00f1c8eb
commit cbe738d5e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -57,7 +57,9 @@ public:
using Observer = Poco::Observer<ParallelSocketAcceptor, ReadableNotification>;
explicit ParallelSocketAcceptor(ServerSocket& socket,
unsigned threads = Poco::Environment::processorCount()):
unsigned threads = Poco::Environment::processorCount(),
const std::string& threadName = ""):
_threadName(threadName),
_socket(socket),
_pReactor(0),
_threads(threads),
@ -70,7 +72,8 @@ public:
ParallelSocketAcceptor(ServerSocket& socket,
SocketReactor& reactor,
unsigned threads = Poco::Environment::processorCount()):
unsigned threads = Poco::Environment::processorCount(), const std::string& threadName = ""):
_threadName(threadName),
_socket(socket),
_pReactor(&reactor),
_threads(threads),
@ -202,7 +205,7 @@ protected:
poco_assert (_threads > 0);
for (unsigned i = 0; i < _threads; ++i)
_reactors.push_back(new ParallelReactor);
_reactors.push_back(new ParallelReactor(_threadName + "#" + std::to_string(i)));
}
ReactorVec& reactors()
@ -228,6 +231,8 @@ private:
ParallelSocketAcceptor(const ParallelSocketAcceptor&);
ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&);
std::string _threadName;
/// Name prefix of sub SocketReactor threads
ServerSocket _socket;
SocketReactor* _pReactor;
unsigned _threads;

View File

@ -48,15 +48,19 @@ class ParallelSocketReactor: public SR
public:
using Ptr = Poco::SharedPtr<ParallelSocketReactor>;
ParallelSocketReactor()
ParallelSocketReactor(const std::string& threadName = "")
{
_thread.start(*this);
if (!threadName.empty())
_thread.setName(threadName);
}
ParallelSocketReactor(const Poco::Timespan& timeout):
ParallelSocketReactor(const Poco::Timespan& timeout, const std::string& threadName = ""):
SR(timeout)
{
_thread.start(*this);
if (!threadName.empty())
_thread.setName(threadName);
}
~ParallelSocketReactor()