Skip to content

Commit cd26d02

Browse files
committed
Merge branch 'devel' of github.com:nim-lang/Nim into devel
2 parents 0dd1811 + ecbbefc commit cd26d02

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/pure/concurrency/cpuload.nim

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ proc advice*(s: var ThreadPoolState): ThreadPoolAdvice =
6060
proc fscanf(c: File, frmt: cstring) {.varargs, importc,
6161
header: "<stdio.h>".}
6262

63-
var f = open("/proc/loadavg")
64-
var b: float
65-
var busy, total: int
66-
fscanf(f,"%lf %lf %lf %ld/%ld",
67-
addr b, addr b, addr b, addr busy, addr total)
68-
f.close()
69-
let cpus = countProcessors()
70-
if busy-1 < cpus:
71-
result = doCreateThread
72-
elif busy-1 >= cpus*2:
73-
result = doShutdownThread
63+
var f: File
64+
if f.open("/proc/loadavg"):
65+
var b: float
66+
var busy, total: int
67+
fscanf(f,"%lf %lf %lf %ld/%ld",
68+
addr b, addr b, addr b, addr busy, addr total)
69+
f.close()
70+
let cpus = countProcessors()
71+
if busy-1 < cpus:
72+
result = doCreateThread
73+
elif busy-1 >= cpus*2:
74+
result = doShutdownThread
75+
else:
76+
result = doNothing
7477
else:
7578
result = doNothing
7679
else:

0 commit comments

Comments
 (0)