mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-04 22:53:08 +00:00
try manually counting sharedptr
This commit is contained in:
parent
ab73d79e7d
commit
343897dab5
@ -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
|
||||
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -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) =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user