1 2 // Copyright Oliver Kowalke 2017. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #include "boost/fiber/numa/pin_thread.hpp" 8 9 extern "C" { 10 #include <sys/errno.h> 11 #include <sys/processor.h> 12 #include <sys/thread.h> 13 } 14 15 #include <system_error> 16 17 #ifdef BOOST_HAS_ABI_HEADERS 18 # include BOOST_ABI_PREFIX 19 #endif 20 21 namespace boost { 22 namespace fibers { 23 namespace numa { 24 25 BOOST_FIBERS_DECL pin_thread(std::uint32_t cpuid)26void pin_thread( std::uint32_t cpuid) { 27 pin_thread( cpuid, ::thread_self() ); 28 } 29 30 BOOST_FIBERS_DECL pin_thread(std::uint32_t cpuid,std::thread::native_handle_type h)31void pin_thread( std::uint32_t cpuid, std::thread::native_handle_type h) { 32 if ( BOOST_UNLIKELY( -1 == ::bindprocessor( BINDTHREAD, h, static_cast< cpu_t >( cpuid) ) ) ) { 33 throw std::system_error( 34 std::error_code( errno, std::system_category() ), 35 "bindprocessor() failed"); 36 } 37 } 38 39 }}} 40 41 #ifdef BOOST_HAS_ABI_HEADERS 42 # include BOOST_ABI_SUFFIX 43 #endif 44