blob: b1db915877dec7880e87872566c0ff8125c25308 (
plain)
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
|
#pragma once
#include <QDebug>
enum {
CORE_WORK = 1,
CORE_IPC = 0,
};
#ifdef _WIN32
#include <windows.h>
class Affinity {
public:
Affinity(int core = CORE_WORK)
{
DWORD_PTR ret = SetThreadAffinityMask(GetCurrentThread(), 1 << core);
if (ret == 0)
qDebug() << "SetThreadAffinityMask" << GetLastError();
last = ret;
}
~Affinity()
{
if (last)
(void) SetThreadAffinityMask(GetCurrentThread(), last);
}
private:
DWORD_PTR last;
};
#else
class Affinity {
public:
Affinity(int core = CORE_WORK) {}
~Affinity() {}
};
#endif
|