make threadpool care about minPoolSize
This commit is contained in:
parent
ec253ada72
commit
8a2f481f99
1 changed files with 10 additions and 0 deletions
|
|
@ -448,12 +448,22 @@ proc nimSpawn3(fn: WorkerProc; data: pointer) {.compilerProc.} =
|
|||
if selectWorker(readyWorker, fn, data): return
|
||||
for i in 0.. <currentPoolSize:
|
||||
if selectWorker(addr(workersData[i]), fn, data): return
|
||||
|
||||
# determine what to do, but keep in mind this is expensive too:
|
||||
# state.calls < maxPoolSize: warmup phase
|
||||
# (state.calls and 127) == 0: periodic check
|
||||
if state.calls < maxPoolSize or (state.calls and 127) == 0:
|
||||
# ensure the call to 'advice' is atomic:
|
||||
if tryAcquire(stateLock):
|
||||
if currentPoolSize < minPoolSize:
|
||||
if not workersData[currentPoolSize].initialized:
|
||||
activateWorkerThread(currentPoolSize)
|
||||
let w = addr(workersData[currentPoolSize])
|
||||
atomicInc currentPoolSize
|
||||
if selectWorker(w, fn, data):
|
||||
release(stateLock)
|
||||
return
|
||||
|
||||
case advice(state)
|
||||
of doNothing: discard
|
||||
of doCreateThread:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue