diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/System.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/System.h')
-rw-r--r-- | CPP/Windows/System.h | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/CPP/Windows/System.h b/CPP/Windows/System.h new file mode 100644 index 0000000..23cb0da --- /dev/null +++ b/CPP/Windows/System.h | |||
@@ -0,0 +1,129 @@ | |||
1 | // Windows/System.h | ||
2 | |||
3 | #ifndef __WINDOWS_SYSTEM_H | ||
4 | #define __WINDOWS_SYSTEM_H | ||
5 | |||
6 | #ifndef _WIN32 | ||
7 | // #include <sched.h> | ||
8 | #include "../../C/Threads.h" | ||
9 | #endif | ||
10 | |||
11 | #include "../Common/MyTypes.h" | ||
12 | |||
13 | namespace NWindows { | ||
14 | namespace NSystem { | ||
15 | |||
16 | |||
17 | #ifdef _WIN32 | ||
18 | |||
19 | UInt32 CountAffinity(DWORD_PTR mask); | ||
20 | |||
21 | struct CProcessAffinity | ||
22 | { | ||
23 | // UInt32 numProcessThreads; | ||
24 | // UInt32 numSysThreads; | ||
25 | DWORD_PTR processAffinityMask; | ||
26 | DWORD_PTR systemAffinityMask; | ||
27 | |||
28 | void InitST() | ||
29 | { | ||
30 | // numProcessThreads = 1; | ||
31 | // numSysThreads = 1; | ||
32 | processAffinityMask = 1; | ||
33 | systemAffinityMask = 1; | ||
34 | } | ||
35 | |||
36 | void CpuZero() | ||
37 | { | ||
38 | processAffinityMask = 0; | ||
39 | } | ||
40 | |||
41 | void CpuSet(unsigned cpuIndex) | ||
42 | { | ||
43 | processAffinityMask |= ((DWORD_PTR)1 << cpuIndex); | ||
44 | } | ||
45 | |||
46 | UInt32 GetNumProcessThreads() const { return CountAffinity(processAffinityMask); } | ||
47 | UInt32 GetNumSystemThreads() const { return CountAffinity(systemAffinityMask); } | ||
48 | |||
49 | BOOL Get(); | ||
50 | |||
51 | BOOL SetProcAffinity() const | ||
52 | { | ||
53 | return SetProcessAffinityMask(GetCurrentProcess(), processAffinityMask); | ||
54 | } | ||
55 | }; | ||
56 | |||
57 | |||
58 | #else // WIN32 | ||
59 | |||
60 | struct CProcessAffinity | ||
61 | { | ||
62 | UInt32 numSysThreads; | ||
63 | |||
64 | UInt32 GetNumSystemThreads() const { return (UInt32)numSysThreads; } | ||
65 | BOOL Get(); | ||
66 | |||
67 | #ifdef _7ZIP_AFFINITY_SUPPORTED | ||
68 | |||
69 | CCpuSet cpu_set; | ||
70 | |||
71 | void InitST() | ||
72 | { | ||
73 | numSysThreads = 1; | ||
74 | CpuSet_Zero(&cpu_set); | ||
75 | CpuSet_Set(&cpu_set, 0); | ||
76 | } | ||
77 | |||
78 | UInt32 GetNumProcessThreads() const { return (UInt32)CPU_COUNT(&cpu_set); } | ||
79 | void CpuZero() { CpuSet_Zero(&cpu_set); } | ||
80 | void CpuSet(unsigned cpuIndex) { CpuSet_Set(&cpu_set, cpuIndex); } | ||
81 | int IsCpuSet(unsigned cpuIndex) const { return CpuSet_IsSet(&cpu_set, cpuIndex); } | ||
82 | // void CpuClr(int cpuIndex) { CPU_CLR(cpuIndex, &cpu_set); } | ||
83 | |||
84 | BOOL SetProcAffinity() const | ||
85 | { | ||
86 | return sched_setaffinity(0, sizeof(cpu_set), &cpu_set) == 0; | ||
87 | } | ||
88 | |||
89 | #else | ||
90 | |||
91 | void InitST() | ||
92 | { | ||
93 | numSysThreads = 1; | ||
94 | } | ||
95 | |||
96 | UInt32 GetNumProcessThreads() const | ||
97 | { | ||
98 | return numSysThreads; | ||
99 | /* | ||
100 | UInt32 num = 0; | ||
101 | for (unsigned i = 0; i < sizeof(cpu_set) * 8; i++) | ||
102 | num += (UInt32)((cpu_set >> i) & 1); | ||
103 | return num; | ||
104 | */ | ||
105 | } | ||
106 | |||
107 | void CpuZero() { } | ||
108 | void CpuSet(unsigned cpuIndex) { UNUSED_VAR(cpuIndex); } | ||
109 | int IsCpuSet(unsigned cpuIndex) const { return (cpuIndex < numSysThreads) ? 1 : 0; } | ||
110 | |||
111 | BOOL SetProcAffinity() const | ||
112 | { | ||
113 | errno = ENOSYS; | ||
114 | return FALSE; | ||
115 | } | ||
116 | |||
117 | #endif | ||
118 | }; | ||
119 | |||
120 | #endif | ||
121 | |||
122 | |||
123 | UInt32 GetNumberOfProcessors(); | ||
124 | |||
125 | bool GetRamSize(UInt64 &size); // returns false, if unknown ram size | ||
126 | |||
127 | }} | ||
128 | |||
129 | #endif | ||