-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadManager.cpp
More file actions
135 lines (119 loc) · 2 KB
/
ThreadManager.cpp
File metadata and controls
135 lines (119 loc) · 2 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "ThreadManager.h"
#include "windows.h"
#include "Game.h"
#include <mutex>
thread_manager thread_manager::TheThread;
void thread_manager::add_to_queue(const std::function<void()>& func)
{
//std::lock_guard<std::mutex>lock(_TM_mutex);
//executeQueue.push(func);
}
thread_manager::thread_manager()
{
numCores = std::thread::hardware_concurrency();
}
thread_manager::~thread_manager()
{
for (auto& t : threads)
t.second->join();
}
void thread_manager::add_thread_and_processor(std::string& name, HANDLE method , int num) {
if (threads.find(name) == threads.end())
{
//threads[name] = std::thread(&method);
set_processor(num, name);
}
}
void thread_manager::set_processor(int CPU, std::string& name)
{
int pro = 0;
switch (CPU)
{
case 1:
pro = 0x02;
break;
case 2:
pro = 0x04;
break;
case 3:
pro = 0x08;
break;
case 4:
pro = 0x10;
break;
case 5:
pro = 0x20;
break;
case 6:
pro = 0x40;
break;
case 7:
pro = 0x80;
break;
case 8:
pro = 0x100;
break;
default:
break;
}
const DWORD_PTR processAffinityMask = pro; // which processor
SetThreadAffinityMask(get_thread_native(name), processAffinityMask);
}
DWORD_PTR thread_manager::set_processor(int CPU)noexcept
{
int pro = 0;
/*switch (NetworkManager::TheNetwork->GetHost())
{
case true:*/
switch (CPU)
{
case 1:
pro = 0x02;
break;
case 2:
pro = 0x04;
break;
case 3:
pro = 0x08;
break;
case 4:
pro = 0x10;
break;
case 5:
pro = 0x20;
break;
case 6:
pro = 0x40;
break;
case 7:
pro = 0x80;
break;
case 8:
pro = 0x100;
break;
/* break;
case false:
switch (CPU)
{
case 5:
pro = 0x06;
break;
case 6:
pro = 0x07;
break;
case 7:
pro = 0x08;
break;
default:
break;
}
break;
default:
break;*/
}
DWORD_PTR processAffinityMask = pro;
return processAffinityMask;
// which processor
//SetThreadAffinityMask(thr.native_handle(), processAffinityMask);
//SetProcessAffinityMask(GetCurrentProcess(), processAffinityMask);
}