bind_processor_freebsd.cpp 696 B

1234567891011121314151617181920212223242526272829
  1. // Copyright Oliver Kowalke 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include "bind_processor.hpp"
  6. extern "C"
  7. {
  8. #include <sys/param.h>
  9. #include <sys/cpuset.h>
  10. }
  11. #include <stdexcept>
  12. #include <boost/config/abi_prefix.hpp>
  13. void bind_to_processor( unsigned int n)
  14. {
  15. cpuset_t cpuset;
  16. CPU_ZERO( & cpuset);
  17. CPU_SET( n, & cpuset);
  18. if ( ::cpuset_setaffinity( CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof( cpuset), & cpuset) == -1)
  19. throw std::runtime_error("::cpuset_setaffinity() failed");
  20. }
  21. #include <boost/config/abi_suffix.hpp>