summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2015-10-15 23:55:29 +0200
committerAndreas Rumpf <rumpf_a@web.de>2015-10-15 23:55:29 +0200
commit612d3f84fbe3ef5c631d98001de52891e6d24930 (patch)
tree0a3b2c1c3c8f3213f90ec35a390ef3ac35f4ec79
parent2f276f8559f103a8c4ea989822226d6dfe7530ea (diff)
parentdda41afe9e5562eddb368ec01f3f76f7206d662f (diff)
downloadNim-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.nim11
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)