mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-20 21:43:08 +00:00
Build fix for FreeBSD
This commit is contained in:
parent
c97943d69d
commit
95983ba168
@ -65,6 +65,7 @@ namespace ZeroTier {
|
|||||||
BSDEthernetTap::BSDEthernetTap(
|
BSDEthernetTap::BSDEthernetTap(
|
||||||
const char *homePath,
|
const char *homePath,
|
||||||
unsigned int concurrency,
|
unsigned int concurrency,
|
||||||
|
bool pinning,
|
||||||
const MAC &mac,
|
const MAC &mac,
|
||||||
unsigned int mtu,
|
unsigned int mtu,
|
||||||
unsigned int metric,
|
unsigned int metric,
|
||||||
@ -74,6 +75,7 @@ BSDEthernetTap::BSDEthernetTap(
|
|||||||
void *arg) :
|
void *arg) :
|
||||||
_handler(handler),
|
_handler(handler),
|
||||||
_concurrency(concurrency),
|
_concurrency(concurrency),
|
||||||
|
_pinning(pinning),
|
||||||
_arg(arg),
|
_arg(arg),
|
||||||
_nwid(nwid),
|
_nwid(nwid),
|
||||||
_mtu(mtu),
|
_mtu(mtu),
|
||||||
@ -425,25 +427,16 @@ void BSDEthernetTap::setMtu(unsigned int mtu)
|
|||||||
void BSDEthernetTap::threadMain()
|
void BSDEthernetTap::threadMain()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
bool _enablePinning = false;
|
|
||||||
char* envvar = std::getenv("ZT_CPU_PINNING");
|
|
||||||
if (envvar) {
|
|
||||||
int tmp = atoi(envvar);
|
|
||||||
if (tmp > 0) {
|
|
||||||
_enablePinning = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for a moment after startup -- wait for Network to finish
|
// Wait for a moment after startup -- wait for Network to finish
|
||||||
// constructing itself.
|
// constructing itself.
|
||||||
Thread::sleep(500);
|
Thread::sleep(500);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < _concurrency; ++i) {
|
for (unsigned int i = 0; i < _concurrency; ++i) {
|
||||||
_rxThreads.push_back(std::thread([this, i, _enablePinning] {
|
_rxThreads.push_back(std::thread([this, i, _pinning] {
|
||||||
|
|
||||||
if (_enablePinning) {
|
if (_pinning) {
|
||||||
int pinCore = i % _concurrency;
|
int pinCore = i % _concurrency;
|
||||||
fprintf(stderr, "pinning thread %d to core %d\n", i, pinCore);
|
fprintf(stderr, "Pinning thread %d to core %d\n", i, pinCore);
|
||||||
pthread_t self = pthread_self();
|
pthread_t self = pthread_self();
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
CPU_ZERO(&cpuset);
|
CPU_ZERO(&cpuset);
|
||||||
@ -452,7 +445,7 @@ void BSDEthernetTap::threadMain()
|
|||||||
int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);
|
int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "failed to pin thread %d to core %d: %s\n", i, pinCore, strerror(errno));
|
fprintf(stderr, "Failed to pin thread %d to core %d: %s\n", i, pinCore, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ public:
|
|||||||
BSDEthernetTap(
|
BSDEthernetTap(
|
||||||
const char *homePath,
|
const char *homePath,
|
||||||
unsigned int concurrency,
|
unsigned int concurrency,
|
||||||
|
bool pinning,
|
||||||
const MAC &mac,
|
const MAC &mac,
|
||||||
unsigned int mtu,
|
unsigned int mtu,
|
||||||
unsigned int metric,
|
unsigned int metric,
|
||||||
@ -65,6 +66,7 @@ private:
|
|||||||
void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
||||||
void *_arg;
|
void *_arg;
|
||||||
unsigned int _concurrency;
|
unsigned int _concurrency;
|
||||||
|
bool _pinning;
|
||||||
uint64_t _nwid;
|
uint64_t _nwid;
|
||||||
Thread _thread;
|
Thread _thread;
|
||||||
std::string _dev;
|
std::string _dev;
|
||||||
|
Loading…
Reference in New Issue
Block a user