15
16 pool_size =
int(os.getenv(
'GYP_LINK_CONCURRENCY', 0))
17 if pool_size:
18 return pool_size
19
20 if sys.platform in ('win32', 'cygwin'):
21 import ctypes
22
23 class MEMORYSTATUSEX(ctypes.Structure):
24 _fields_ = [
25 ("dwLength", ctypes.c_ulong),
26 ("dwMemoryLoad", ctypes.c_ulong),
27 ("ullTotalPhys", ctypes.c_ulonglong),
28 ("ullAvailPhys", ctypes.c_ulonglong),
29 ("ullTotalPageFile", ctypes.c_ulonglong),
30 ("ullAvailPageFile", ctypes.c_ulonglong),
31 ("ullTotalVirtual", ctypes.c_ulonglong),
32 ("ullAvailVirtual", ctypes.c_ulonglong),
33 ("sullAvailExtendedVirtual", ctypes.c_ulonglong),
34 ]
35
36 stat = MEMORYSTATUSEX(dwLength=ctypes.sizeof(MEMORYSTATUSEX))
37 ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
38
39 mem_limit =
max(1, stat.ullTotalPhys // (4 * (2**30)))
40 hard_cap =
max(1,
int(os.getenv(
'GYP_LINK_CONCURRENCY_MAX', 2**32)))
41 return min(mem_limit, hard_cap)
42 elif sys.platform.startswith('linux'):
43 if os.path.exists("/proc/meminfo"):
44 with open("/proc/meminfo") as meminfo:
45 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB')
46 for line in meminfo:
47 match = memtotal_re.match(line)
48 if not match:
49 continue
50
51 return max(1,
int(match.group(1)) // (8 * (2**20)))
52 return 1
53 elif sys.platform == 'darwin':
54 try:
56 subprocess.check_output(['sysctl', '-n', 'hw.memsize']))
57
58
59 return max(1, avail_bytes // (4 * (2**30)))
60 except Exception:
61 return 1
62 else:
63
64 return 1
65
66
static float max(float r, float g, float b)
static float min(float r, float g, float b)
def GetDefaultConcurrentLinks()