Skip to content

Commit

Permalink
try to behave better on leorize's laptop (#41)
Browse files Browse the repository at this point in the history
* try to behave better on leorize's laptop

* bump semaphores version requirement
  • Loading branch information
disruptek authored Jun 8, 2021
1 parent db363b5 commit 9a31806
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions balls.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "MIT"
# requires newTreeFrom
requires "https://github.com/disruptek/grok >= 0.5.0 & < 1.0.0"
requires "https://github.com/disruptek/ups < 1.0.0"
requires "https://github.com/disruptek/semaphores >= 0.0.4 & < 1.0.0"

bin = @["balls"] # build the binary for basic test running
installExt = @["nim"] # we need to install balls.nim also
Expand Down
19 changes: 17 additions & 2 deletions balls/runner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ when not compileOption"threads":
import std/rlocks

import ups/sanitize
import semaphores

import balls/spec
import balls/style
Expand Down Expand Up @@ -79,6 +80,12 @@ proc shortPath(fn: string): string =
proc `$`(p: Profile): string =
"$#: $# $# $#" % [ short p.fn, $p.cp, $p.gc, $p.opt ]

proc corePhore(): Semaphore =
## produce a semaphore according to the number of available cores
result.init 314
for core in 1 .. countProcessors():
signal result

template cmper(f: untyped) {.dirty.} =
result = system.cmp(a.`f`, b.`f`)
if result != 0:
Expand Down Expand Up @@ -403,14 +410,22 @@ proc shouldPass(p: Profile): bool =
if p.gc <= arc:
result = true

var cores = corePhore()

proc performThreaded(p: Payload) {.thread.} =
## run perform, but do it in a thread with a lock on the compilation cache
var ran: string
{.gcsafe.}:
ran = p.profile.run
p.status[] = Wait
withRLock p.cache[]:
p.status[] = Runs
p.status[] = perform p.profile
wait cores
try:
p.status[] = Runs
p.status[] = perform p.profile
finally:
# indicate that we're done with the core
signal cores

# we don't conditionally raise anymore because we don't join threads, so
# we cannot catch it easily in the parent thread; hence we rely upon the
Expand Down

0 comments on commit 9a31806

Please sign in to comment.