Changed MDP3 producer to honor new thread configuration.

This commit is contained in:
Pedro Pinto committed 2018-10-03 15:45:29 +00:00
1 parent 0833dce43d
commit ae3e721f62
6 files changed
+62 -25

No files matched your search

+34 -20
View File
@@ -24,6 +24,23 @@ config::ThreadGroupCfg get_thread_cfg(std::string const &name) {
fmt::format("No configuration found for thread {}", name));
}
std::vector<uint32_t> get_affinity(std::string const &name) {
std::vector<uint32_t> result;
#ifndef WIN32
auto cfg = get_thread_cfg(name);
if (cfg.exclude()) {
auto total_cpus = sysconf(_SC_NPROCESSORS_ONLN);
for (int i = 0; i < total_cpus; i++)
if (std::find(cfg.core().begin(), cfg.core().end(), i) == cfg.core().end())
result.push_back(i);
} else {
for (auto const &core : cfg.core())
result.push_back(core);
}
#endif
return result;
}
#ifndef WIN32
void configure_thread(std::string const &name,
config::ThreadGroupCfg const &cfg, pthread_t t) {
@@ -54,46 +71,43 @@ void configure_thread(std::string const &name,
#endif
void configure_current_thread(std::string const &name) {
#ifndef WIN32
#ifndef WIN32
configure_thread(name, get_thread_cfg(name), pthread_self());
#endif
#endif
os::set_thread_name(name);
}
void configure_current_thread(std::string const &name,
config::ThreadGroupCfg const &cfg) {
#ifndef WIN32
#ifndef WIN32
configure_thread(name, cfg, pthread_self());
#endif
#endif
os::set_thread_name(name);
}
std::thread make_thread_from_function(std::string const &name,
std::function<void()> const &c) {
auto result = std::thread(
[c,name] () {
os::set_thread_name(name);
c();
});
#ifndef WIN32
auto result = std::thread([c, name]() {
os::set_thread_name(name);
c();
});
#ifndef WIN32
configure_thread(name, get_thread_cfg(name), result.native_handle());
#endif
#endif
return result;
}
std::thread make_thread_from_function(std::string const &name,
std::function<void()> const &c,
config::ThreadGroupCfg const &cfg) {
auto result = std::thread(
[c,name] () {
os::set_thread_name(name);
c();
});
#ifndef WIN32
auto result = std::thread([c, name]() {
os::set_thread_name(name);
c();
});
#ifndef WIN32
configure_thread(name, cfg, result.native_handle());
#endif
#endif
return result;
}