mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Moar threadz
This commit is contained in:
parent
2da162bed7
commit
101a3a7d74
2 changed files with 26 additions and 20 deletions
|
@ -292,36 +292,42 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_tapProcessorThread = std::thread([this] {
|
for(int k=0;k<2;++k) {
|
||||||
MAC to,from;
|
_tapProcessorThread[k] = std::thread([this] {
|
||||||
std::pair<void *,int> qi;
|
MAC to,from;
|
||||||
while (_tapq.get(qi)) {
|
std::pair<void *,int> qi;
|
||||||
uint8_t *const b = reinterpret_cast<uint8_t *>(qi.first);
|
while (_tapq.get(qi)) {
|
||||||
if (b) {
|
uint8_t *const b = reinterpret_cast<uint8_t *>(qi.first);
|
||||||
to.setTo(b, 6);
|
if (b) {
|
||||||
from.setTo(b + 6, 6);
|
to.setTo(b, 6);
|
||||||
unsigned int etherType = Utils::ntoh(((const uint16_t *)b)[6]);
|
from.setTo(b + 6, 6);
|
||||||
_handler(_arg, nullptr, _nwid, from, to, etherType, 0, (const void *)(b + 14),(unsigned int)(qi.second - 14));
|
unsigned int etherType = Utils::ntoh(((const uint16_t *)b)[6]);
|
||||||
{
|
_handler(_arg, nullptr, _nwid, from, to, etherType, 0, (const void *)(b + 14),(unsigned int)(qi.second - 14));
|
||||||
std::lock_guard<std::mutex> l(_buffers_l);
|
{
|
||||||
_buffers.push_back(qi.first);
|
std::lock_guard<std::mutex> l(_buffers_l);
|
||||||
}
|
_buffers.push_back(qi.first);
|
||||||
} else break;
|
}
|
||||||
}
|
} else break;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxEthernetTap::~LinuxEthernetTap()
|
LinuxEthernetTap::~LinuxEthernetTap()
|
||||||
{
|
{
|
||||||
(void)::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
|
(void)::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
|
||||||
_tapq.post(std::pair<void *,int>(nullptr,0));
|
for(int k=0;k<64;++k) {
|
||||||
|
_tapq.post(std::pair<void *,int>(nullptr,0));
|
||||||
|
}
|
||||||
|
|
||||||
::close(_fd);
|
::close(_fd);
|
||||||
::close(_shutdownSignalPipe[0]);
|
::close(_shutdownSignalPipe[0]);
|
||||||
::close(_shutdownSignalPipe[1]);
|
::close(_shutdownSignalPipe[1]);
|
||||||
|
|
||||||
_tapReaderThread.join();
|
_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)
|
for(std::vector<void *>::iterator i(_buffers.begin());i!=_buffers.end();++i)
|
||||||
free(*i);
|
free(*i);
|
||||||
|
|
|
@ -71,7 +71,7 @@ private:
|
||||||
int _shutdownSignalPipe[2];
|
int _shutdownSignalPipe[2];
|
||||||
std::atomic_bool _enabled;
|
std::atomic_bool _enabled;
|
||||||
std::thread _tapReaderThread;
|
std::thread _tapReaderThread;
|
||||||
std::thread _tapProcessorThread;
|
std::thread _tapProcessorThread[2];
|
||||||
std::mutex _buffers_l;
|
std::mutex _buffers_l;
|
||||||
std::vector<void *> _buffers;
|
std::vector<void *> _buffers;
|
||||||
BlockingQueue< std::pair<void *,int> > _tapq;
|
BlockingQueue< std::pair<void *,int> > _tapq;
|
||||||
|
|
Loading…
Add table
Reference in a new issue