• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/pthread.h>
11 }
12 
13 #include <system_error>
14 
15 #ifdef BOOST_HAS_ABI_HEADERS
16 # include BOOST_ABI_PREFIX
17 #endif
18 
19 namespace boost {
20 namespace fibers {
21 namespace numa {
22 
23 BOOST_FIBERS_DECL
pin_thread(std::uint32_t cpuid)24 void pin_thread( std::uint32_t cpuid) {
25     pin_thread( cpuid, PTHREAD_SELFTID_NP);
26 }
27 
28 BOOST_FIBERS_DECL
pin_thread(std::uint32_t cpuid,std::thread::native_handle_type h)29 void pin_thread( std::uint32_t cpuid, std::thread::native_handle_type h) {
30     pthread_spu_t spu;
31     int err = ::pthread_processor_bind_np( PTHREAD_BIND_FORCED_NP,
32                                            & spu,
33                                            static_cast< pthread_spu_t >( cpuid),
34                                            h);
35     if ( BOOST_UNLIKELY( 0 != err) )
36         throw std::system_error(
37                 std::error_code( err, std::system_category() ),
38                 "pthread_processor_bind_np() failed");
39     }
40 }
41 
42 }}}
43 
44 #ifdef BOOST_HAS_ABI_HEADERS
45 # include BOOST_ABI_SUFFIX
46 #endif
47