mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-05 23:23:10 +00:00
switch to custom sharedptr
This commit is contained in:
parent
fed5a906eb
commit
97d4e68f5d
@ -43,6 +43,11 @@ proc decr*[T](x: var SharedPtr[T]) =
|
||||
else:
|
||||
echo "SharedPtr: decr: ", repr x.val.pointer, " ", x.cnt[], " tp: ", $(typeof(T))
|
||||
|
||||
proc release*[T](x: var SharedPtr[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, " cnt: ", x.cnt.repr, " tp: ", $(typeof(T))
|
||||
@ -74,7 +79,6 @@ template newSharedPtr*[T](val: T): SharedPtr[T] =
|
||||
|
||||
proc newSharedPtr*[T](t: typedesc[T]): SharedPtr[T] =
|
||||
## Returns a shared pointer. It is not initialized,
|
||||
## so reading from it before writing to it is undefined behaviour!
|
||||
result.cnt = cast[ptr int](allocShared0(sizeof(result.cnt)))
|
||||
result.val = cast[typeof(result.val)](allocShared0(sizeof(result.val[])))
|
||||
result.cnt[] = 0
|
||||
|
||||
@ -63,7 +63,7 @@ proc newThreadResult*[T](
|
||||
proc release*[T](res: var TResult[T]) {.raises: [].} =
|
||||
## release TResult and it's ThreadSignal
|
||||
res[].signal.release()
|
||||
res.decr()
|
||||
sharedptr.release(res)
|
||||
|
||||
proc success*[T](ret: TResult[T], value: T) =
|
||||
## convenience wrapper for `TResult` to replicate
|
||||
|
||||
@ -32,10 +32,11 @@ proc threadTest() =
|
||||
|
||||
test "check put":
|
||||
# echo "\n\n=== put ==="
|
||||
let res1 = await sds.put(key1, data)
|
||||
check res1.isOk
|
||||
# print "res1: ", res1
|
||||
GC_fullCollect()
|
||||
for i in 1..3:
|
||||
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