Tune thread count based on hardware concurrency.

This commit is contained in:
Adam Ierymenko 2020-11-18 22:42:00 -05:00
parent f934a09baa
commit 7b14aeb53e
No known key found for this signature in database
GPG Key ID: C8877CF2D7A5D7F3
2 changed files with 7 additions and 7 deletions

View File

@ -184,14 +184,14 @@ LinuxEthernetTap::LinuxEthernetTap(
(void)::pipe(_shutdownSignalPipe);
for(unsigned int t=0;t<2;++t) {
_tapReaderThread[t] = std::thread([this, t]{
for(unsigned int tn=0,tc=(unsigned int)std::thread::hardware_concurrency();tn<=tc;++tn) {
_tapReaderThreads.push_back(std::thread([this, tn]{
fd_set readfds,nullfds;
int n,nfds,r;
void *buf = nullptr;
std::vector<void *> buffers;
if (t == 0) {
if (tn == 0) {
struct ifreq ifr;
memset(&ifr,0,sizeof(ifr));
strcpy(ifr.ifr_name,_dev.c_str());
@ -298,7 +298,7 @@ LinuxEthernetTap::LinuxEthernetTap(
}
}
}
});
}));
}
_tapProcessorThread = std::thread([this] {
@ -331,8 +331,8 @@ LinuxEthernetTap::~LinuxEthernetTap()
::close(_shutdownSignalPipe[0]);
::close(_shutdownSignalPipe[1]);
_tapReaderThread[0].join();
_tapReaderThread[1].join();
for(std::vector<std::thread>::iterator t(_tapReaderThreads.begin());t!=_tapReaderThreads.end();++t)
t->join();
_tapProcessorThread.join();
for(std::vector<void *>::iterator i(_buffers.begin());i!=_buffers.end();++i)

View File

@ -70,7 +70,7 @@ private:
int _fd;
int _shutdownSignalPipe[2];
std::atomic_bool _enabled;
std::thread _tapReaderThread[2];
std::vector<std::thread> _tapReaderThreads;
std::thread _tapProcessorThread;
std::mutex _buffers_l;
std::vector<void *> _buffers;