From 178f7e0fbd26da6adb033b7d27e2c9fe76cabc9e Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 18 Sep 2023 14:10:54 -0700 Subject: [PATCH] back to ref TaskCtx --- datastore/threads/threadproxyds.nim | 3 ++- tests/datastore/testthreadproxyds.nim | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/datastore/threads/threadproxyds.nim b/datastore/threads/threadproxyds.nim index 486a16b..2439e8c 100644 --- a/datastore/threads/threadproxyds.nim +++ b/datastore/threads/threadproxyds.nim @@ -53,7 +53,8 @@ type # needed for the fsds, but it is expensive! proc addrOf*[T](ctx: ref TaskCtx[T]): ptr TaskCtx[T] = - cast[ptr TaskCtx[T]](ctx) + result = cast[ptr TaskCtx[T]](ctx) + echo "ADDR_OF: ", result.pointer.repr proc new*[T]( ctx: typedesc[TaskCtx[T]], diff --git a/tests/datastore/testthreadproxyds.nim b/tests/datastore/testthreadproxyds.nim index 8cf4d3d..a9cbfb9 100644 --- a/tests/datastore/testthreadproxyds.nim +++ b/tests/datastore/testthreadproxyds.nim @@ -4,6 +4,7 @@ import std/os import std/cpuinfo import std/algorithm import std/importutils +import std/atomics import pkg/asynctest import pkg/chronos @@ -146,11 +147,11 @@ suite "Test ThreadDatastore cancelations": test "Should monitor signal and cancel": var signal = ThreadSignalPtr.new().tryGet() - ctx = TaskCtx[void]( - ds: addr sqlStore, - signal: signal) + ctx = TaskCtx[void].new( + ds= sqlStore, + signal= signal) fut = newFuture[void]("signalMonitor") - threadArgs = (cast[ptr TaskCtx[void]](ctx), addr fut) + threadArgs: (ptr TaskCtx[void], ptr Future[void]) = (addrOf(ctx), addr fut) var thread: Thread[type threadArgs] @@ -166,7 +167,7 @@ suite "Test ThreadDatastore cancelations": waitFor asyncTask() createThread(thread, threadTask, threadArgs) - ctx.cancelled = true + ctx.cancelled.store(true, moAcquireRelease) check: ctx.signal.fireSync.tryGet joinThreads(thread) @@ -177,13 +178,11 @@ suite "Test ThreadDatastore cancelations": test "Should monitor and not cancel": var signal = ThreadSignalPtr.new().tryGet() - res = ThreadResult[void]() - ctx = TaskCtx[void]( - ds: addr sqlStore, - res: addr res, - signal: signal) + ctx = TaskCtx[void].new( + ds= sqlStore, + signal= signal) fut = newFuture[void]("signalMonitor") - threadArgs = (addr ctx, addr fut) + threadArgs = (addrOf ctx, addr fut) var thread: Thread[type threadArgs] @@ -199,7 +198,7 @@ suite "Test ThreadDatastore cancelations": waitFor asyncTask() createThread(thread, threadTask, threadArgs) - ctx.cancelled = false + ctx.cancelled.store(false, moAcquireRelease) check: ctx.signal.fireSync.tryGet joinThreads(thread)