try manually counting sharedptr

This commit is contained in:
Jaremy Creechley 2023-09-14 15:21:12 -07:00
parent ab73d79e7d
commit 343897dab5
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 7 additions and 6 deletions

View File

@ -50,8 +50,7 @@ proc new*[D: DataBuffer](tp: typedesc[D], size: int = 0): D =
))
echoed "DataBuffer:new: ", result.unsafeRawPtr().repr,
" tp ", $(typeof(D)),
" @ ", result[].buf.pointer.repr,
" -> ", result.toString().repr
" @ ", result[].buf.pointer.repr
proc new*[T: byte | char; D: DataBuffer](tp: typedesc[D], data: openArray[T]): D =
## allocate new buffer and copies indata from openArray

View File

@ -49,12 +49,12 @@ type
## Shared ownership reference counting pointer.
container*: ptr tuple[value: T, cnt: int, manual: bool]
proc incr*[T](a: var SharedPtr[T]) =
proc incr*[T](a: SharedPtr[T]) =
if a.container != nil:
let res = atomicAddFetch(a.cnt, 1, ATOMIC_RELAXED)
echoed "SharedPtr: incr: ", res
proc decr*[T](x: var SharedPtr[T]) =
proc decr*[T](x: SharedPtr[T]) =
if x.container != nil:
let res = atomicSubFetch(addr x.container.cnt, 1, ATOMIC_ACQUIRE)
if res == 0:
@ -65,7 +65,7 @@ proc decr*[T](x: var SharedPtr[T]) =
else:
echoed "SharedPtr:NOT CALLED:child:destructor: ", $(typeof(x[]))
deallocShared(x.container)
x.container = nil
# x.container = nil # alas
else:
echoed "SharedPtr: decr: ", x.container.pointer.repr, " cnt: ", x.container.cnt, " tp: ", $(typeof(T))

View File

@ -147,7 +147,7 @@ proc putTask*(
ret.success()
discard sig.fireSync()
# ret.release()
sig.decr()
echoed "putTask: FINISH\n"
import then
@ -187,9 +187,11 @@ proc put*(
let val = ret.convert(void)
putRes.complete(val)
).cancelled(proc() =
sig.decr()
echoed "put request cancelled "
discard
).catch(proc(e: ref CatchableError) =
sig.decr()
doAssert false, "will not be triggered"
)
).catch(proc(e: ref CatchableError) =