Moar threadz

This commit is contained in:
Adam Ierymenko 2020-11-16 21:49:51 -05:00
parent 2da162bed7
commit 101a3a7d74
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
2 changed files with 26 additions and 20 deletions

View file

@ -292,7 +292,8 @@ LinuxEthernetTap::LinuxEthernetTap(
}
});
_tapProcessorThread = std::thread([this] {
for(int k=0;k<2;++k) {
_tapProcessorThread[k] = std::thread([this] {
MAC to,from;
std::pair<void *,int> qi;
while (_tapq.get(qi)) {
@ -310,18 +311,23 @@ LinuxEthernetTap::LinuxEthernetTap(
}
});
}
}
LinuxEthernetTap::~LinuxEthernetTap()
{
(void)::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
for(int k=0;k<64;++k) {
_tapq.post(std::pair<void *,int>(nullptr,0));
}
::close(_fd);
::close(_shutdownSignalPipe[0]);
::close(_shutdownSignalPipe[1]);
_tapReaderThread.join();
_tapProcessorThread.join();
for(int k=0;k<2;++k) {
_tapProcessorThread[k].join();
}
for(std::vector<void *>::iterator i(_buffers.begin());i!=_buffers.end();++i)
free(*i);

View file

@ -71,7 +71,7 @@ private:
int _shutdownSignalPipe[2];
std::atomic_bool _enabled;
std::thread _tapReaderThread;
std::thread _tapProcessorThread;
std::thread _tapProcessorThread[2];
std::mutex _buffers_l;
std::vector<void *> _buffers;
BlockingQueue< std::pair<void *,int> > _tapq;