mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-09 00:53:08 +00:00
fix counts
This commit is contained in:
parent
d755bd0562
commit
8fbfc3b976
@ -27,7 +27,7 @@ proc `=destroy`*(x: var DataBufferHolder) =
|
||||
## copy pointer implementation
|
||||
if x.buf != nil:
|
||||
# when isMainModule or true:
|
||||
# echo "buffer: FREE: ", repr x.buf.pointer
|
||||
echo "databuffer: FREE: ", repr x.buf.pointer
|
||||
deallocShared(x.buf)
|
||||
|
||||
proc len*(a: DataBuffer): int = a[].size
|
||||
|
||||
@ -32,7 +32,7 @@ proc decr*[T](x: var SharedPtr[T]) =
|
||||
if x.val != nil and x.cnt != nil:
|
||||
let res = atomicSubFetch(x.cnt, 1, ATOMIC_ACQUIRE)
|
||||
if res == 0:
|
||||
echo "SharedPtr: FREE: ", repr x.val.pointer, " ", x.cnt[], " tp: ", $(typeof(T))
|
||||
echo "SharedPtr: FREE: ", repr x.val.pointer, " ", x.cnt.repr, " tp: ", $(typeof(T))
|
||||
when compiles(`=destroy`(x[])):
|
||||
echo "DECR FREE: ", $(typeof(x[]))
|
||||
`=destroy`(x[])
|
||||
@ -41,22 +41,24 @@ proc decr*[T](x: var SharedPtr[T]) =
|
||||
x.val = nil
|
||||
x.cnt = nil
|
||||
else:
|
||||
echo "SharedPtr: decr: ", repr x.val.pointer, " ", x.cnt[], " tp: ", $(typeof(T))
|
||||
echo "SharedPtr: decr: ", repr x.val.pointer, " ", x.cnt.repr, " tp: ", $(typeof(T))
|
||||
|
||||
proc release*[T](x: var SharedPtr[T]) =
|
||||
echo "SharedPtr: release: ", $(typeof(T))
|
||||
x.decr()
|
||||
x.val = nil
|
||||
x.cnt = nil
|
||||
|
||||
proc `=destroy`*[T](x: var SharedPtr[T]) =
|
||||
if x.val != nil:
|
||||
echo "SharedPtr: destroy: ", repr x.val.pointer.repr, " cnt: ", x.cnt.pointer.repr, " tp: ", $(typeof(T))
|
||||
echo "SharedPtr: destroy: ", repr x.val.pointer.repr, " cnt: ", x.cnt.repr, " tp: ", $(typeof(T))
|
||||
decr(x)
|
||||
|
||||
proc `=dup`*[T](src: SharedPtr[T]): SharedPtr[T] =
|
||||
if src.val != nil and src.cnt != nil:
|
||||
discard atomicAddFetch(src.cnt, 1, ATOMIC_RELAXED)
|
||||
result.val = src.val
|
||||
result.cnt = src.cnt
|
||||
|
||||
proc `=copy`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) =
|
||||
if src.val != nil and src.cnt != nil:
|
||||
@ -64,6 +66,7 @@ proc `=copy`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) =
|
||||
discard atomicAddFetch(src.cnt, 1, ATOMIC_RELAXED)
|
||||
`=destroy`(dest)
|
||||
dest.val = src.val
|
||||
dest.cnt = src.cnt
|
||||
|
||||
proc newSharedPtr*[T](val: sink Isolated[T]): SharedPtr[T] {.nodestroy.} =
|
||||
## Returns a shared pointer which shares,
|
||||
@ -72,7 +75,7 @@ proc newSharedPtr*[T](val: sink Isolated[T]): SharedPtr[T] {.nodestroy.} =
|
||||
result.val = cast[typeof(result.val)](allocShared(sizeof(result.val[])))
|
||||
result.cnt[] = 1
|
||||
result.val[] = extract val
|
||||
echo "SharedPtr: alloc: ", result.val.pointer.repr, " tp: ", $(typeof(T))
|
||||
echo "SharedPtr: alloc: ", result.val.pointer.repr, " cnt: ", result.cnt.repr, " tp: ", $(typeof(T))
|
||||
|
||||
template newSharedPtr*[T](val: T): SharedPtr[T] =
|
||||
newSharedPtr(isolate(val))
|
||||
@ -82,7 +85,7 @@ proc newSharedPtr*[T](t: typedesc[T]): SharedPtr[T] =
|
||||
result.cnt = cast[ptr int](allocShared0(sizeof(result.cnt)))
|
||||
result.val = cast[typeof(result.val)](allocShared0(sizeof(result.val[])))
|
||||
result.cnt[] = 1
|
||||
echo "SharedPtr: alloc: ", result.val.pointer.repr, " tp: ", $(typeof(T))
|
||||
echo "SharedPtr: alloc: ", result.val.pointer.repr, " cnt: ", result.cnt.repr, " tp: ", $(typeof(T))
|
||||
|
||||
proc isNil*[T](p: SharedPtr[T]): bool {.inline.} =
|
||||
p.val == nil
|
||||
|
||||
@ -128,6 +128,8 @@ proc putTask*(
|
||||
db: DataBuffer,
|
||||
) =
|
||||
|
||||
# var ret = ret
|
||||
|
||||
without key =? kb.toKey(), err:
|
||||
ret.failure(err)
|
||||
|
||||
@ -140,6 +142,7 @@ proc putTask*(
|
||||
ret.success()
|
||||
|
||||
discard ret.fireSync()
|
||||
# ret.release()
|
||||
|
||||
proc put*(
|
||||
ret: TResult[void],
|
||||
|
||||
@ -61,10 +61,11 @@ proc newThreadResult*[T](
|
||||
res[].sig = await SharedSignal.new()
|
||||
res
|
||||
|
||||
proc release*[T](res: var TResult[T]) {.raises: [].} =
|
||||
## release TResult and it's ThreadSignal
|
||||
# res[].signal.release()
|
||||
sharedptr.release(res)
|
||||
# proc release*[T](res: var TResult[T]) {.raises: [].} =
|
||||
# ## release TResult and it's ThreadSignal
|
||||
# # res[].signal.release()
|
||||
# sharedptr.release(res)
|
||||
|
||||
proc wait*[T](res: TResult[T]): Future[void] =
|
||||
res[].sig.wait()
|
||||
proc fireSync*[T](res: TResult[T]): Result[bool, string] =
|
||||
|
||||
@ -107,3 +107,5 @@ suite "Share buffer test":
|
||||
finally:
|
||||
b.release()
|
||||
check intref[] == 0
|
||||
|
||||
# TODO: add async test
|
||||
|
||||
@ -14,7 +14,7 @@ import pkg/datastore/threadproxyds
|
||||
import ./dscommontests
|
||||
import ./querycommontests
|
||||
|
||||
# import pretty
|
||||
import pretty
|
||||
|
||||
proc threadTest() =
|
||||
suite "Test Basic ThreadProxyDatastore":
|
||||
@ -32,11 +32,10 @@ proc threadTest() =
|
||||
|
||||
test "check put":
|
||||
# echo "\n\n=== put ==="
|
||||
for i in 1..3:
|
||||
let res1 = await sds.put(key1, data)
|
||||
check res1.isOk
|
||||
# print "res1: ", res1
|
||||
GC_fullCollect()
|
||||
let res1 = await sds.put(key1, data)
|
||||
check res1.isOk
|
||||
print "res1: ", res1
|
||||
GC_fullCollect()
|
||||
|
||||
threadTest()
|
||||
GC_fullCollect()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user