Add cpu_limit to ninja link pool on windows.

This will cap the number of links at the min of cpu_count v. mem / 4G.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/24106005

git-svn-id: http://gyp.googlecode.com/svn/trunk@1724 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index 01df42f..1d4b913 100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -1514,7 +1514,13 @@
     stat.dwLength = ctypes.sizeof(stat)
     ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
 
-    return max(1, stat.ullTotalPhys / (4 * (2 ** 30)))  # total / 4GB
+    mem_limit = max(1, stat.ullTotalPhys / (4 * (2 ** 30)))  # total / 4GB
+    cpu_limit = 1
+    try:
+      cpu_limit = multiprocessing.cpu_count()
+    except NotImplementedError:
+      pass
+    return min(mem_limit, cpu_limit)
   elif sys.platform.startswith('linux'):
     with open("/proc/meminfo") as meminfo:
       memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB')