fixup databuffer

This commit is contained in:
Jaremy Creechley 2023-09-26 16:02:42 -07:00
parent abfd12f7a6
commit 892ec385ee
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 14 additions and 11 deletions

View File

@ -27,8 +27,10 @@ proc `=destroy`*(x: var DataBufferHolder) =
# echo "buffer: FREE: ", repr x.buf.pointer
deallocShared(x.buf)
proc len*(a: DataBuffer): int = a[].size
proc capacity*(a: DataBuffer): int = a[].cap
proc len*(a: DataBuffer): int =
if a.isNil: 0 else: a[].size
proc capacity*(a: DataBuffer): int =
if a.isNil: 0 else: a[].cap
proc isNil*(a: DataBuffer): bool = smartptrs.isNil(a)

View File

@ -242,7 +242,7 @@ proc queryTask[DB](
(?!QResult).err(qh.error())
else:
# otherwise manually an set empty ok result
ctx[].res.ok (KeyId.none, DataBuffer.new())
ctx[].res.ok (KeyId.none, DataBuffer(), )
discard ctx[].signal.fireSync()
var handle = qh.get()
@ -260,7 +260,7 @@ proc queryTask[DB](
discard ctx[].signal.fireSync()
# set final result
(?!QResult).ok((KeyId.none, DataBuffer.new()))
(?!QResult).ok((KeyId.none, DataBuffer()))
method query*(
self: ThreadDatastore,
@ -313,16 +313,17 @@ method query*(
iter.next = next
return success iter
proc new*(
self: type ThreadDatastore,
ds: Datastore,
withLocks = static false,
tp: Taskpool): ?!ThreadDatastore =
proc new*(self: type ThreadDatastore,
backend: ThreadBackendKinds,
withLocks = static false,
tp: Taskpool
): ?!ThreadDatastore =
doAssert tp.numThreads > 1, "ThreadDatastore requires at least 2 threads"
success ThreadDatastore(
tp: tp,
ds: ds,
ds: ThreadBackend(),
withLocks: withLocks,
queryLock: newAsyncLock(),
semaphore: AsyncSemaphore.new(tp.numThreads - 1))
semaphore: AsyncSemaphore.new(tp.numThreads - 1)
)