Ticket #8266: bind_processor_darwin.cpp

File bind_processor_darwin.cpp, 752 bytes (added by marco.serantoni@…, 9 years ago)

(for performance)

Line 
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
9extern "C"
10{
11#include <mach/mach.h>
12#include <mach/thread_policy.h>
13}
14
15#include <stdexcept>
16
17#include <boost/config/abi_prefix.hpp>
18
19void bind_to_processor( unsigned int n)
20{
21 int errno_;
22 thread_affinity_policy_data_t affinity;
23
24 errno_ = thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (thread_policy_t)&affinity, THREAD_AFFINITY_POLICY_COUNT);
25
26 if ( errno_ != 0)
27 throw std::runtime_error("::pthread_setaffinity_np() failed");
28
29}
30
31#include <boost/config/abi_suffix.hpp>