29#if defined(PTL_WINDOWS)
34# include <sys/sysctl.h>
57 return std::this_thread::get_id();
65 return std::thread::hardware_concurrency();
75 size_t count_len =
sizeof(count);
76 sysctlbyname(
"hw.physicalcpu", &count, &count_len,
nullptr, 0);
77 return static_cast<unsigned>(count);
78#elif defined(PTL_LINUX)
79 unsigned core_id_count = 0;
80 std::ifstream ifs(
"/proc/cpuinfo");
83 std::set<std::string> core_ids;
86 std::string line = {};
90 if(line.find(
"core id") != std::string::npos)
92 for(std::string itr : {
"core id",
":",
" ",
"\t" })
94 static auto _npos = std::string::npos;
96 while((_pos = line.find(itr)) != _npos)
97 line = line.replace(_pos, itr.length(),
"");
99 core_ids.insert(line);
102 core_id_count =
static_cast<unsigned>(core_ids.size());
103 if(core_id_count > 0)
104 return core_id_count;
131#if defined(__linux__) || defined(_AIX)
132 cpu_set_t _cpu_set{};
135 CPU_SET(_cpu, &_cpu_set);
136 return (pthread_setaffinity_np(pthread_self(),
sizeof(cpu_set_t), &_cpu_set) == 0);
148#if defined(__linux__) || defined(_AIX)
149 return (pthread_setschedprio(pthread_self(), _prio) == 0);
161#if defined(__linux__) || defined(_AIX)
162 cpu_set_t _cpu_set{};
164 CPU_SET(_cpu, &_cpu_set);
165 return (pthread_setaffinity_np(
static_cast<pthread_t
>(_t),
sizeof(cpu_set_t),
178#if defined(__linux__) || defined(_AIX)
179 return (pthread_setschedprio(
static_cast<pthread_t
>(_t), _prio) == 0);
unsigned GetNumberOfCores()
unsigned GetNumberOfPhysicalCpus()
bool SetPinAffinity(int idx)
bool SetThreadPriority(int _v)
void SetThreadId(int aNewValue)
std::thread::native_handle_type NativeThread
void ConsumeParameters(Args &&...)