Fallback to doNothing if /proc/loadavg cant be opened (#7123)

This commit is contained in:
Yuriy Glukhov 2018-01-22 15:52:22 +03:00 • committed by Andreas Rumpf
commit ecbbefcc83

View file

@ -60,17 +60,20 @@ proc advice*(s: var ThreadPoolState): ThreadPoolAdvice =
proc fscanf(c: File, frmt: cstring) {.varargs, importc, proc fscanf(c: File, frmt: cstring) {.varargs, importc,
header: "<stdio.h>".} header: "<stdio.h>".}
var f = open("/proc/loadavg") var f: File
var b: float if f.open("/proc/loadavg"):
var busy, total: int var b: float
fscanf(f,"%lf %lf %lf %ld/%ld", var busy, total: int
addr b, addr b, addr b, addr busy, addr total) fscanf(f,"%lf %lf %lf %ld/%ld",
f.close() addr b, addr b, addr b, addr busy, addr total)
let cpus = countProcessors() f.close()
if busy-1 < cpus: let cpus = countProcessors()
result = doCreateThread if busy-1 < cpus:
elif busy-1 >= cpus*2: result = doCreateThread
result = doShutdownThread elif busy-1 >= cpus*2:
result = doShutdownThread
else:
result = doNothing
else: else:
result = doNothing result = doNothing
else: else: