diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-10-15 23:55:29 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-10-15 23:55:29 +0200 |
commit | 612d3f84fbe3ef5c631d98001de52891e6d24930 (patch) | |
tree | 0a3b2c1c3c8f3213f90ec35a390ef3ac35f4ec79 | |
parent | 2f276f8559f103a8c4ea989822226d6dfe7530ea (diff) | |
parent | dda41afe9e5562eddb368ec01f3f76f7206d662f (diff) | |
download | Nim-612d3f84fbe3ef5c631d98001de52891e6d24930.tar.gz |
Merge pull request #3437 from nim-lang/threadpool-isready
Implement isReady procedure in threadpool module.
-rw-r--r-- | lib/pure/concurrency/threadpool.nim | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim index 72e744d52..2603835dd 100644 --- a/lib/pure/concurrency/threadpool.nim +++ b/lib/pure/concurrency/threadpool.nim @@ -267,6 +267,17 @@ proc awaitAny*(flowVars: openArray[FlowVarBase]): int = result = -1 destroySemaphore(ai.cv) +proc isReady*(fv: FlowVarBase): bool = + ## Determines whether the specified ``FlowVarBase``'s value is available. + ## + ## If ``true`` awaiting ``fv`` will not block. + if fv.usesSemaphore and not fv.awaited: + acquire(fv.cv.L) + result = fv.cv.counter > 0 + release(fv.cv.L) + else: + result = true + proc nimArgsPassingDone(p: pointer) {.compilerProc.} = let w = cast[ptr Worker](p) signal(w.taskStarted) |