]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright Oliver Kowalke 2009. | |
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 "bind_processor.hpp" | |
8 | ||
9 | extern "C" | |
10 | { | |
11 | #include <pthread.h> | |
12 | #include <sched.h> | |
13 | } | |
14 | ||
15 | #include <stdexcept> | |
16 | ||
17 | #include <boost/config/abi_prefix.hpp> | |
18 | ||
19 | void bind_to_processor( unsigned int n) | |
20 | { | |
21 | cpu_set_t cpuset; | |
22 | CPU_ZERO( & cpuset); | |
23 | CPU_SET( n, & cpuset); | |
24 | ||
25 | int errno_( ::pthread_setaffinity_np( ::pthread_self(), sizeof( cpuset), & cpuset) ); | |
26 | if ( errno_ != 0) | |
27 | throw std::runtime_error("::pthread_setaffinity_np() failed"); | |
28 | } | |
29 | ||
30 | #include <boost/config/abi_suffix.hpp> |