]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
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 <errno.h> | |
11 | #include <sys/param.h> | |
12 | #include <sys/cpuset.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 | |
26 | void pin_thread( std::uint32_t cpu_id) { | |
27 | cpuset_t mask; | |
28 | CPU_ZERO( & mask); | |
29 | CPU_SET( cpu_id, & mask); | |
30 | if ( BOOST_UNLIKELY( 0 != ::cpuset_setaffinity( CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof( mask), & mask) ) ) { | |
31 | throw std::system_error( | |
32 | std::error_code( errno, std::system_category() ), | |
33 | "::cpuset_setaffinity() failed"); | |
34 | } | |
35 | } | |
36 | ||
37 | }}} | |
38 | ||
39 | #ifdef BOOST_HAS_ABI_HEADERS | |
40 | # include BOOST_ABI_SUFFIX | |
41 | #endif |