mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 23:05:27 +00:00
setMaxPoolSize improvements
This commit is contained in:
@@ -134,7 +134,7 @@ proc await*(fv: FlowVarBase) =
|
||||
proc finished(fv: FlowVarBase) =
|
||||
doAssert fv.ai.isNil, "flowVar is still attached to an 'awaitAny'"
|
||||
# we have to protect against the rare cases where the owner of the flowVar
|
||||
# simply disregards the flowVar and yet the "flowVarr" has not yet written
|
||||
# simply disregards the flowVar and yet the "flowVar" has not yet written
|
||||
# anything to it:
|
||||
await(fv)
|
||||
if fv.data.isNil: return
|
||||
@@ -207,6 +207,7 @@ proc `^`*[T](fv: FlowVar[T]): T =
|
||||
## blocks until the value is available and then returns this value.
|
||||
await(fv)
|
||||
when T is string or T is seq:
|
||||
# XXX closures? deepCopy?
|
||||
result = cast[T](fv.data)
|
||||
else:
|
||||
result = fv.blob
|
||||
@@ -264,6 +265,10 @@ proc slave(w: ptr Worker) {.thread.} =
|
||||
w.shutdown = false
|
||||
atomicDec currentPoolSize
|
||||
|
||||
var
|
||||
workers: array[MaxThreadPoolSize, TThread[ptr Worker]]
|
||||
workersData: array[MaxThreadPoolSize, Worker]
|
||||
|
||||
proc setMinPoolSize*(size: range[1..MaxThreadPoolSize]) =
|
||||
## sets the minimal thread pool size. The default value of this is 4.
|
||||
minPoolSize = size
|
||||
@@ -272,10 +277,10 @@ proc setMaxPoolSize*(size: range[1..MaxThreadPoolSize]) =
|
||||
## sets the minimal thread pool size. The default value of this
|
||||
## is ``MaxThreadPoolSize``.
|
||||
maxPoolSize = size
|
||||
|
||||
var
|
||||
workers: array[MaxThreadPoolSize, TThread[ptr Worker]]
|
||||
workersData: array[MaxThreadPoolSize, Worker]
|
||||
if currentPoolSize > maxPoolSize:
|
||||
for i in maxPoolSize..currentPoolSize-1:
|
||||
let w = addr(workersData[i])
|
||||
w.shutdown = true
|
||||
|
||||
proc activateThread(i: int) {.noinline.} =
|
||||
workersData[i].taskArrived = createCondVar()
|
||||
|
||||
Reference in New Issue
Block a user