aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/System.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Windows/System.cpp58
1 files changed, 51 insertions, 7 deletions
diff --git a/CPP/Windows/System.cpp b/CPP/Windows/System.cpp
index 3a14b77..dbe287a 100644
--- a/CPP/Windows/System.cpp
+++ b/CPP/Windows/System.cpp
@@ -4,6 +4,7 @@
4 4
5#ifndef _WIN32 5#ifndef _WIN32
6#include <unistd.h> 6#include <unistd.h>
7#include <limits.h>
7#ifdef __APPLE__ 8#ifdef __APPLE__
8#include <sys/sysctl.h> 9#include <sys/sysctl.h>
9#else 10#else
@@ -74,7 +75,7 @@ BOOL CProcessAffinity::Get()
74 return TRUE; 75 return TRUE;
75 */ 76 */
76 77
77 #ifdef _7ZIP_AFFINITY_SUPPORTED 78 #ifdef Z7_AFFINITY_SUPPORTED
78 79
79 // numSysThreads = sysconf(_SC_NPROCESSORS_ONLN); // The number of processors currently online 80 // numSysThreads = sysconf(_SC_NPROCESSORS_ONLN); // The number of processors currently online
80 if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) != 0) 81 if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) != 0)
@@ -93,7 +94,7 @@ BOOL CProcessAffinity::Get()
93 94
94UInt32 GetNumberOfProcessors() 95UInt32 GetNumberOfProcessors()
95{ 96{
96 #ifndef _7ZIP_ST 97 #ifndef Z7_ST
97 long n = sysconf(_SC_NPROCESSORS_CONF); // The number of processors configured 98 long n = sysconf(_SC_NPROCESSORS_CONF); // The number of processors configured
98 if (n < 1) 99 if (n < 1)
99 n = 1; 100 n = 1;
@@ -110,7 +111,8 @@ UInt32 GetNumberOfProcessors()
110 111
111#ifndef UNDER_CE 112#ifndef UNDER_CE
112 113
113#if !defined(_WIN64) && defined(__GNUC__) 114#if !defined(_WIN64) && \
115 (defined(__MINGW32_VERSION) || defined(Z7_OLD_WIN_SDK))
114 116
115typedef struct _MY_MEMORYSTATUSEX { 117typedef struct _MY_MEMORYSTATUSEX {
116 DWORD dwLength; 118 DWORD dwLength;
@@ -131,7 +133,7 @@ typedef struct _MY_MEMORYSTATUSEX {
131 133
132#endif 134#endif
133 135
134typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer); 136typedef BOOL (WINAPI *Func_GlobalMemoryStatusEx)(MY_LPMEMORYSTATUSEX lpBuffer);
135 137
136#endif // !UNDER_CE 138#endif // !UNDER_CE
137 139
@@ -155,9 +157,11 @@ bool GetRamSize(UInt64 &size)
155 #else 157 #else
156 158
157 #ifndef UNDER_CE 159 #ifndef UNDER_CE
158 GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) 160 const
159 (void *)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "GlobalMemoryStatusEx"); 161 Func_GlobalMemoryStatusEx fn = Z7_GET_PROC_ADDRESS(
160 if (globalMemoryStatusEx && globalMemoryStatusEx(&stat)) 162 Func_GlobalMemoryStatusEx, ::GetModuleHandleA("kernel32.dll"),
163 "GlobalMemoryStatusEx");
164 if (fn && fn(&stat))
161 { 165 {
162 size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); 166 size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys);
163 return true; 167 return true;
@@ -231,4 +235,44 @@ bool GetRamSize(UInt64 &size)
231 235
232#endif 236#endif
233 237
238
239unsigned long Get_File_OPEN_MAX()
240{
241 #ifdef _WIN32
242 return (1 << 24) - (1 << 16); // ~16M handles
243 #else
244 // some linux versions have default open file limit for user process of 1024 files.
245 long n = sysconf(_SC_OPEN_MAX);
246 // n = -1; // for debug
247 // n = 9; // for debug
248 if (n < 1)
249 {
250 // n = OPEN_MAX; // ???
251 // n = FOPEN_MAX; // = 16 : <stdio.h>
252 #ifdef _POSIX_OPEN_MAX
253 n = _POSIX_OPEN_MAX; // = 20 : <limits.h>
254 #else
255 n = 30; // our limit
256 #endif
257 }
258 return (unsigned long)n;
259 #endif
260}
261
262unsigned Get_File_OPEN_MAX_Reduced_for_3_tasks()
263{
264 unsigned long numFiles_OPEN_MAX = NSystem::Get_File_OPEN_MAX();
265 const unsigned delta = 10; // the reserve for another internal needs of process
266 if (numFiles_OPEN_MAX > delta)
267 numFiles_OPEN_MAX -= delta;
268 else
269 numFiles_OPEN_MAX = 1;
270 numFiles_OPEN_MAX /= 3; // we suppose that we have up to 3 tasks in total for multiple file processing
271 numFiles_OPEN_MAX = MyMax(numFiles_OPEN_MAX, (unsigned long)3);
272 unsigned n = (UInt32)(UInt32)-1;
273 if (n > numFiles_OPEN_MAX)
274 n = (unsigned)numFiles_OPEN_MAX;
275 return n;
276}
277
234}} 278}}