mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-18 20:47:53 +00:00
Build fix for FreeBSD
This commit is contained in:
parent
c97943d69d
commit
95983ba168
@ -65,6 +65,7 @@ namespace ZeroTier {
|
||||
BSDEthernetTap::BSDEthernetTap(
|
||||
const char *homePath,
|
||||
unsigned int concurrency,
|
||||
bool pinning,
|
||||
const MAC &mac,
|
||||
unsigned int mtu,
|
||||
unsigned int metric,
|
||||
@ -74,6 +75,7 @@ BSDEthernetTap::BSDEthernetTap(
|
||||
void *arg) :
|
||||
_handler(handler),
|
||||
_concurrency(concurrency),
|
||||
_pinning(pinning),
|
||||
_arg(arg),
|
||||
_nwid(nwid),
|
||||
_mtu(mtu),
|
||||
@ -425,25 +427,16 @@ void BSDEthernetTap::setMtu(unsigned int mtu)
|
||||
void BSDEthernetTap::threadMain()
|
||||
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
|
||||
// constructing itself.
|
||||
Thread::sleep(500);
|
||||
|
||||
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;
|
||||
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();
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
@ -452,7 +445,7 @@ void BSDEthernetTap::threadMain()
|
||||
int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
BSDEthernetTap(
|
||||
const char *homePath,
|
||||
unsigned int concurrency,
|
||||
bool pinning,
|
||||
const MAC &mac,
|
||||
unsigned int mtu,
|
||||
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 *_arg;
|
||||
unsigned int _concurrency;
|
||||
bool _pinning;
|
||||
uint64_t _nwid;
|
||||
Thread _thread;
|
||||
std::string _dev;
|
||||
|
Loading…
Reference in New Issue
Block a user