diff options
author | Araq <rumpf_a@web.de> | 2014-11-03 12:01:07 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-11-03 12:01:07 +0100 |
commit | 8853023fd8c0ecd241b22a674db62723f4bf0305 (patch) | |
tree | 0e578fa8899731ce82609ee72a8e1a35f1474b49 /lib/pure | |
parent | adad2d5f4aa9940278e4baab25d757246c74d4a2 (diff) | |
parent | 1b4dd6f61e311e774b218173b9b4f47c9a78ac8d (diff) | |
download | Nim-8853023fd8c0ecd241b22a674db62723f4bf0305.tar.gz |
Merge branch 'bigbreak' of https://github.com/Araq/Nimrod into bigbreak
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/oids.nim | 2 | ||||
-rw-r--r-- | lib/pure/osproc.nim | 16 |
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index 7c58a2dda..0dc8e3c15 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -55,7 +55,7 @@ proc oidToString*(oid: Oid, str: cstring) = str[24] = '\0' proc `$`*(oid: Oid): string = - result = newString(25) + result = newString(24) oidToString(oid, result) var diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 0557b26f7..500ec7fb7 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -235,11 +235,13 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, - n = countProcessors()): int {.rtl, extern: "nosp$1", - tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} = + n = countProcessors(), + beforeRunEvent: proc(idx: int) = nil): int + {.rtl, extern: "nosp$1", + tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = ## executes the commands `cmds` in parallel. Creates `n` processes ## that execute in parallel. The highest return value of all processes - ## is returned. + ## is returned. Runs `beforeRunEvent` before running each command. when defined(posix): # poParentStreams causes problems on Posix, so we simply disable it: var options = options - {poParentStreams} @@ -250,6 +252,8 @@ proc execProcesses*(cmds: openArray[string], newSeq(q, n) var m = min(n, cmds.len) for i in 0..m-1: + if beforeRunEvent != nil: + beforeRunEvent(i) q[i] = startCmd(cmds[i], options=options) when defined(noBusyWaiting): var r = 0 @@ -263,6 +267,8 @@ proc execProcesses*(cmds: openArray[string], echo(err) result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) + if beforeRunEvent != nil: + beforeRunEvent(i) q[r] = startCmd(cmds[i], options=options) r = (r + 1) mod n else: @@ -274,6 +280,8 @@ proc execProcesses*(cmds: openArray[string], #echo(outputStream(q[r]).readLine()) result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) + if beforeRunEvent != nil: + beforeRunEvent(i) q[r] = startCmd(cmds[i], options=options) inc(i) if i > high(cmds): break @@ -282,6 +290,8 @@ proc execProcesses*(cmds: openArray[string], if q[j] != nil: close(q[j]) else: for i in 0..high(cmds): + if beforeRunEvent != nil: + beforeRunEvent(i) var p = startCmd(cmds[i], options=options) result = max(waitForExit(p), result) close(p) |