From a2b74aeb33690fb4d03226be7a98fd27801b315b Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 9 Feb 2024 21:11:49 -0700 Subject: [PATCH] fix decrement and free in channel --- src/apatheia/queues.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/apatheia/queues.nim b/src/apatheia/queues.nim index f72df84..85707d6 100644 --- a/src/apatheia/queues.nim +++ b/src/apatheia/queues.nim @@ -1,4 +1,3 @@ -import std/channels import ./types @@ -9,15 +8,21 @@ import chronos/threadsync export types type + ChanPtr[T] = ptr Channel[T] +proc allocSharedChannel[T](): ChanPtr[T] = + cast[ChanPtr[T]](allocShared0(sizeof(Channel[T]))) + +type AsyncQueue*[T] = object signal: ThreadSignalPtr - chan*: T + chan*: ChanPtr[T] proc new*[T](tp: typedesc[AsyncQueue[T]]): AsyncQueue[T] {.raises: [ApatheiaSignalErr].} = let res = ThreadSignalPtr.new() if res.isErr(): raise newException(ApatheiaSignalErr, msg: res.err()) - else: - result.signal = res.get() + result.signal = res.get() + result.chan = allocSharedChannel() +