add nextSignal using mutex

This commit is contained in:
Jaremy Creechley 2023-09-27 13:16:30 -07:00
parent 1fd80c6f2b
commit c51d354f72
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 9 additions and 1 deletions

View File

@ -41,6 +41,7 @@ type
signal: ThreadSignalPtr
running: bool ## used to mark when a task worker is running
cancelled: bool ## used to cancel a task before it's started
nextSignal: (Lock, Cond)
TaskCtx*[T] = SharedPtr[TaskCtxObj[T]]
## Task context object.
@ -72,6 +73,13 @@ proc setDone[T](ctx: TaskCtx[T]) =
# withLock(ctxLock):
ctx[].running = false
proc waitSync*(sig: var (Lock, Cond)) =
withLock(sig[0]):
wait(sig[1], sig[0])
proc fireSync*(sig: var (Lock, Cond)) =
withLock(sig[0]):
signal(sig[1])
proc acquireSignal(): ?!ThreadSignalPtr =
let signal = ThreadSignalPtr.new()
if signal.isErr():

View File

@ -24,7 +24,7 @@ import ./querycommontests
const
NumThreads = 20 # IO threads aren't attached to CPU count
ThreadTestLoops {.intdefine.} = 10
ThreadTestLoops {.intdefine.} = 100
N = ThreadTestLoops
for i in 1..N: