JayBeams  0.1
Another project to have fun coding.
reconfigure_thread.cpp
Go to the documentation of this file.
2 #include <jb/detail/os_error.hpp>
3 
4 #include <pthread.h>
5 #include <sched.h>
6 
8  pthread_t self = pthread_self();
9 
10  sched_param param;
11  param.sched_priority = config.native_priority();
12  int r =
13  pthread_setschedparam(self, config.native_scheduling_policy(), &param);
14  if (not config.ignore_setup_errors()) {
15  os_check_error(r, "reconfigure_this_thread() - setting scheduling");
16  }
17 
18  if (config.affinity().count() > 0) {
19  r = pthread_setaffinity_np(
20  self, sizeof(cpu_set_t),
21  const_cast<cpu_set_t*>(config.affinity().native_handle()));
22  if (not config.ignore_setup_errors()) {
23  os_check_error(r, "reconfigure_this_thread() - setting affinity");
24  }
25  }
26 
27  if (config.name() != "") {
28  r = pthread_setname_np(self, config.name().c_str());
29  if (not config.ignore_setup_errors()) {
30  os_check_error(r, "reconfigure_this_thread() - setting name");
31  }
32  }
33 }
int native_priority() const
jb::config_attribute< thread_config, jb::cpu_set > affinity
jb::config_attribute< thread_config, bool > ignore_setup_errors
Hold the configuration to initialize threads.
int native_scheduling_policy() const
void reconfigure_this_thread(thread_config const &config)
Change the current thread parameters based on the configuration.
void os_check_error(int result, char const *msg)
Check the value of result and raise an exception if it is -1.
Definition: os_error.cpp:5
jb::config_attribute< thread_config, std::string > name