blob: 45ca5b27b13de0edb6e70b4d57633ecc4a7b12c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <iostream>
#include <boost/config.hpp>
#ifdef BOOST_WINDOWS
#include <windows.h>
#endif
void set_process_affinity(int core)
{
#if defined (__APPLE__)
return;
#elif defined(BOOST_WINDOWS)
DWORD_PTR mask = 1;
for (int i = 0; i < core; ++i)
{
mask <<= 1;
}
::SetProcessAffinityMask(::GetCurrentProcess(), core);
#elif defined(BOOST_HAS_PTHREADS)
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(core, &cpuset);
if (0 != ::pthread_setaffinity_np(::pthread_self(), sizeof(cpuset), &cpuset))
{
std::cout << "pthread_setaffinity_np - ERROR" << std::endl;
}
#endif
}
void set_thread_high_priority()
{
#if defined(__APPLE__)
return;
#elif defined(BOOST_WINDOWS)
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#elif defined(BOOST_HAS_PTHREADS)
pthread_attr_t attr;
int policy = 0;
int max_prio_for_policy = 0;
::pthread_attr_init(&attr);
::pthread_attr_getschedpolicy(&attr, &policy);
max_prio_for_policy = ::sched_get_priority_max(policy);
if (0 != ::pthread_setschedprio(::pthread_self(), max_prio_for_policy))
{
std::cout << "pthread_setschedprio - ERROR" << std::endl;
}
::pthread_attr_destroy(&attr);
#endif
}
|